提交代码
Position Find( List L, ElementType X ) {
List p = L;
for ( p=L; p; p=p->Next) {
if ( p->Data == X)
return p;
}
return ERROR;
}
List Insert( List L, ElementType X, Position P ) {
List temp;
List head = L;
List beforeP;
if ( L==NULL ) {
L = (List)malloc(sizeof(struct LNode));
L->Data = X;
L->Next = NULL;
return L;
}
if ( P==NULL ) {
//P in the tail
beforeP = L;
while (beforeP != NULL) {
if (beforeP->Next == NULL) {
break;
}
beforeP = beforeP->Next;
}
temp = (List)malloc(sizeof(struct LNode));
temp->Data = X;
temp->Next = NULL;
beforeP->Next = temp;
return head;
}
if ( P==L ) {
//P in the head
temp = (List)malloc(sizeof(struct LNode));
temp->Data = X;
temp->Next = L;
return temp;
}
beforeP = L;
while (L != NULL) {
if ( L==P ) {
temp = (List)malloc(sizeof(struct LNode))