List MakeEmpty(){
List L=(List)malloc(sizeof(struct LNode));
L->Next=NULL;
return L;
}
Position Find( List L, ElementType X ){
List p=L->Next;
while(p){
if(p->Data==X){
return p;
}
p=p->Next;
}
return ERROR;
}
bool Insert( List L, ElementType X, Position P ){
List p=L;
List q=(List) malloc(sizeof(struct LNode));
q->Data=X;
while(p){
if(p->Next==P){
q->Next=p->Next;
p->Next=q;
return true;
}
p=p->Next;
}
printf("Wrong Position for Insertion\n");
return false;
}
bool Delete( List L, Position P ){
List p=L->Next,pre=L;
while(p){
if(p==P){
pre->Next=p->Next;
return true;
}
pre=p;
p=p->Next;
}
printf("Wrong Position for Deletion\n");
return false;
}
6-6 带头结点的链式表操作集 (20 分)
最新推荐文章于 2021-09-07 19:37:19 发布