#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
int data;
LNode* next;
}LNode,*LinkList;
//尾插法建立单链表
LinkList List_TailInsert(LinkList& L) {
int x;
L = (LinkList)malloc(sizeof(LNode));//建立头节点
LNode* s=L; //指向头指针
LNode* p=L; //指向头指针,表尾指针
scanf("%d\n", &x);
while (x != 9999) {
s = (LNode*)malloc(sizeof(LNode));
s ->data = x;
p->next = s;
p = s;
scanf("%d\n", &x);
}
p->next = NULL;//尾指针置为空
return L;
}
//头插法建立单链表
LinkList List_HeadInsert(LinkList& L) {
LNode* s;
int x;
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
scanf("%d\n", &x);
while (x != 9999) {
s = (LNode*)malloc(sizeof(LNode));
s->data = x;
s->next = L->next;
L->next = s;
scanf("%d\n", &x);
}
return L;
}
05-20
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-13
5181
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交