![image.png](https://i-blog.csdnimg.cn/blog_migrate/316cfb8fde01cdc777b1c356cec7f08c.png)
函数代码:
List MakeEmpty() {
List L = (List)malloc(sizeof(struct LNode));
L->Next = NULL;
return L;
}
Position Find(List L, ElementType X) {
Position p = L->Next;
while (p&&p->Data != X) {
p = p->Next;
}
if (p != NULL && p->Data == X) {
return p;
}
return ERROR;
}
bool Insert(List L, ElementType X, Position P) {
if (L == NULL) {
printf("Wrong Position for Insertion\n");
return false;
}
Position temp = L;
struct LNode *newLNode;
newLNode = (struct LNode *)malloc(sizeof(struct LNode));
newLNode->Data = X;
while (temp && temp->Next != P) {
temp = temp->Next;
}
if (temp != NULL && temp->Next == P) {
newLNode->Next = temp->Next;
temp->Next = newLNode;
return true;
}
printf("Wrong Position for Insertion\n");
return false;
}
bool Delete(List L, Position P) {
if (L == NULL || P == NULL) {
printf("Wrong Position for Deletion\n");
return false;
}
Position temp = L;
while (temp && temp->Next != P) {
temp = temp->Next;
}
if (temp != NULL && temp->Next == P) {
temp->Next = temp->Next->Next;
return true;
}
printf("Wrong Position for Deletion\n");
return false;
}