6-5 链式表操作集
Position Find( List L, ElementType X ){
while(L){
if(L->Data == X){
return L;
}
L = L->Next;
}
return ERROR;
}
List Insert( List L, ElementType X, Position P ){
if(P == L){
List Node = (List)malloc(sizeof(List));
Node->Data = X;
Node->Next = L;
return Node;
}
List q = L;
while(q){
if(q->Next == P){
List Node = (List)malloc(sizeof(List));
Node->Data = X;
Node->Next = q->Next;
q->Next = Node;
return L;
}
q = q->Next;
}
printf("Wrong Position for Insertion\n");
return ERROR;
}
List Delete( List L, Position P ){
if(L == P){
return L->Next;
}
List q = L;
while(q){
if(q->Next == P){
q->Next = q->Next->Next;
return L;
}
q = q->Next;
}
printf("Wrong Position for Deletion\n");
return ERROR;
}