作者:toto333 | 来源:互联网 | 2024-11-29 17:57
代码:
#include
#include
typedef struct LNode {int data;struct LNode *next;
}LNode,*LinkList;
LNode *GetElem(LinkList L, int i) {int j = 1;LNode *p = L->next;if (i == 0) return L;if (i < 1) return NULL;while (p != NULL && j < i) {p = p->next; j++;}return p;
}
bool InitList(LinkList &L) {L = (LNode *)malloc(sizeof(LNode));if (L == NULL) { return false;}L->next = NULL; return true;
}
bool Empty(LinkList L) {if (L->next == NULL) {return true;}else {return false;}
}
bool InsertNextNode(LNode *p, int e) {if (p == NULL) {return false;}LNode *s = (LNode *)malloc(sizeof(LNode));if (s == NULL) { return false;}s->data = e;s->next = p->next;p->next = s;return true;
}
bool ListInsert(LinkList &L, int i, int e) {if (i < 1) {return false;}LNode *p;p = L;int j = 0;while (p!=NULL && j < i-1) {
结果: