链表的一些基本操作的实现

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAXSIZE 100
#define OVERFLOW -1
#define OK 1
#define ERROR 0
typedef struct Lnode {
int data;
struct Lnode* next;
L = new Lnode;
L->next = NULL;
return OK;
}
if (L->next) //非空返回0
return 0;
else //空返回1
return 1;
}
int GetElem(LinkList L, int i,int &e) {
Lnode* p;
p=L->next; int j = 1;
while (p&& j < i) {
p = p->next;
++j;
}
if (!p || j > i) return ERROR;
e = p->data;
return OK;
}
L = new Lnode;
L->next = NULL;
for (int i = n; i > 0; --i)
{
Lnode* p;
p = new Lnode;
printf("请输入数字:\n");
scanf_s("%d" ,&p->data);
p->next = L->next;
L->next = p;

}
}
Lnode* p;
while (L) {
p = L;
L = L->next;
delete p;
}
return OK;
}
Lnode *p;
p = L->next;
int i = 0;
while (p) {
i++;
p = p->next;
}
return i;
}
int main() {
InitList(L);
int e = 0;
printf("---------------------------------------------分割线---------------------------  --------------—\n");
GetElem(L, 1, e);
printf("打印第1个元素:%d\n",e);
GetElem(L, 2, e);
printf("打印第2个元素:%d\n", e);
GetElem(L, 3, e);
printf("打印第3个元素:%d\n", e);
GetElem(L, 4, e);
printf("打印第4个元素:%d\n", e);
GetElem(L, 5, e);
printf("打印第5个元素:%d\n", e);
printf("单链表的长度是:%d\n", ListLength(L));
DestroyList(L);
printf("单链表是否为空(0不空，1空)？。。。。结果是:%d\n", ListEmpty(L));
return 0;
}



05-10 2143

12-29 536
04-21 3936
06-04 404
01-10 6万+
04-22 783
07-23 2万+
09-20 1991
07-25 920
04-08 2594
04-06 1万+
11-05 9245
07-27 2万+
06-10 1万+
09-26 629
10-05 2964
09-13 2万+
06-06 3404
03-27 1万+
06-16 1万+