MCPcopy Create free account
hub / github.com/142vip/408CSFamily / CreateListWithStartNode

Function CreateListWithStartNode

code/ds/LinkList.cpp:2–26  ·  view source on GitHub ↗

单链表头插法

Source from the content-addressed store, hash-verified

1// 单链表头插法
2LinkList CreateListWithStartNode(LinkList &L){
3
4 LNode *s;
5 int x;
6 L=(LinkList)malloc(sizeof(LNode)); // 创建头结点L
7 L->next=NULL; // 初始化空链表
8
9 // 控制台输入值
10 scanf("%d",&x);
11
12 // 输入9999 表示结束
13 while(x!==9999){
14 // 开辟新结点存储空间
15 s=(LNode*)malloc(sizeof(LNode));
16 // 结点数据域赋值
17 s->data=x;
18 // 修改指针,新结点插入表中【注意:L->next为头结点的指针域】
19 s->next=L->next;
20 L->next=s;
21 scanf("%d",&x);
22 }
23
24 // 返回单链表
25 return L;
26}
27
28// 单链表尾插法
29LinkList CreateListWithEndNode(LinkList &L){

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected