1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
//循环单链表的初始化,建立,插入,查找,删除。//
//Author:Wang Yong //
//Date: 2010.8.20 //
#include <stdio.h>
#include <stdlib.h>
typedef
int
ElemType;
///
//定义结点类型
typedef
struct
Node
{
ElemType data;
struct
Node *next;
}Node,*LinkList;
//
//循环单链表的创建,采用尾插法建立单链表
LinkList LinkListCreatT()
{
LinkList L,r,p;
L = (Node *)
malloc
(
sizeof
(Node));
//初始化链表
L->next = L;
r = L;
//r始终指向最后一个结点
ElemType x;
while
(
scanf
(
"%d"
,&x) != EOF)
{
p = (Node *)
malloc
(
sizeof
(Node));
p->data = x;
p->next = r->next;
r->next = p;
r = p;
}
r->next = L;
return
L;
}
int
main()
{
LinkList list,start;
list = LinkListCreatT();
for
(start = list->next ;start != list;start = start->next)
printf
(
"%d "
,start->data);
printf
(
"\n"
);
return
0;
}
|
转载于:https://www.cnblogs.com/heyp/p/3797261.html