标签:单链,return,LNode,int,NULL,next,false,数据结构,语言 From: https://blog.csdn.net/m0_60936698/article/details/140849768typedef struct LNode{
Elemtype data;
struct LNode *next;
}LNode , *Linklist;
//初始化单链表(不带头节点)
bool InitList (LinkList &L){
L=NULL;
return true;
}
插入
bool ListInsert(LinkList &L,int i,Elemtype e){
if(i<1)
return false;
if(i==1){
LNode *s = (LNode *) malloc(sizeof(Node));
s->data = e;
s->next=L;
l=s;
return ture;
}
LNode *P;
int j=1;
p=L;
while(p!=NULL && j<i-1){
p=p->next;
j++;
}
if(p==NULL)
return false;
LNode *s = (LNode * )malloc(sizeof(LNode));
s->data = e;
s -> next = p->next;
p -> next = s;
return true;
}
//初始化单链表(带头结点)
bool InitList(LinkList &L){
L = (LNode*) malloc (sizeof(LNode));
if(L==NULL)
return false;
L -> next = NULL;
return true;
}
//插入
bool ListInsert(LinkList &L,int i,Elemtype e){
if(i<1)
return false;
LNode *p
int j=0;
p = L;
while (p!=NULL && j<i-1){
p=p->next;
j++;
if(i=NULL){
return false;
LNode *s = (LNode *)malloc(sizeof(LNode));
s->data = e;
s->next=p->next;
p-next=s;
return ture
}
}
//删除
bool ListDelete(LinkList &L,int i,Elemtype e){
if(i<1)
return false;
LNode *p
int j=0;
p = L;
while (p!=NULL && j<i-1){
p=p->next;
j++;
if(i=NULL){
return false;
if(p->next == NULL)
return false;
LNode *q = p->next;
e = q ->data
p - next = q - next;
free(q);
return ture
}
//按位查找(带头节点)
LNode * Getelem(LinkList L,int i){
if(i<0)
return false;
LNode *p
int j=0;
p = L;
while (p!=NULL && j<i){
p=p->next;
j++;
}
return p;
}
//按值查找
LNode * locateElem ( LinkList L ,Elemtype e){
LNode *p = L -> next;
while(p !=NULL && p->data!=e)
p=p->next;
return p;
}
void test(){
LinkListL;
InitList(L);
}