-
Notifications
You must be signed in to change notification settings - Fork 1
/
linklist.c
123 lines (108 loc) · 2.03 KB
/
linklist.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "stdio.h"
#include "stdlib.h"
struct node
{
int Data;
struct node *Next;
};
typedef struct node *LinkListNode;
typedef struct list
{
LinkListNode head;
LinkListNode tail;
int totalnumber;
}*List;
List CreateLinkList()
{
List list;
LinkListNode Lnode;
list = malloc(sizeof(List));
Lnode = (LinkListNode)malloc(sizeof(struct node));
if(Lnode != NULL)
{
Lnode->Data = 0;
Lnode->Next = NULL;
list->head = Lnode;
list->tail = Lnode;
list->totalnumber = 0;
}
return list;
}
int AppendLinkListNode(List L,int value)
{
LinkListNode Lnode;
if(NULL == L)
{
return -1;
}
Lnode = (LinkListNode)malloc(sizeof(struct node));
if(Lnode != NULL)
{
Lnode->Data = value;
Lnode->Next = NULL;
}
L->tail->Next = Lnode;
L->tail = L->tail->Next;
L->totalnumber++;
return 0;
}
int main(void)
{
int N;
int index;
int value = 0;
List LinkList = NULL;
LinkListNode p = NULL;
LinkListNode q = NULL;
scanf("%d",&N);
LinkList = CreateLinkList();
if(LinkList == NULL)
{
// printf("link list is null\n");
return 0;
}
else
{
//printf("the link is not null\n");
}
while(1)
{
//printf("the value is %d\n",value);
scanf("%d",&value);
// printf("the value is %d\n",value);
if(0 >= value)
{
break;
}
else
{
//printf("the value is %d\n",value);
AppendLinkListNode(LinkList,value);
}
}
// printf("out of the loop\n");
p = LinkList->head;
q = LinkList->head;
if(N > LinkList->totalnumber)
{
printf("NULL");
}
while(--N && q != NULL)
{
q = q->Next;
}
#if 1
while(q!=NULL)
{
q = q->Next;
p = p->Next;
}
//p = p->Next;
#endif
if(p!=NULL)
{
printf("%d",p->Data);
}
//#endif
return 0;
}