-
Notifications
You must be signed in to change notification settings - Fork 0
/
temporary.c
53 lines (39 loc) · 840 Bytes
/
temporary.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
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node *next;
} elem;
elem *CreateList(elem *list, int num) {
elem *tmp = NULL;
tmp = (elem *)malloc(sizeof(elem));
if (tmp) {
tmp -> data = num;
tmp -> next = NULL;
if (list) {
tmp -> next = list;
list = tmp;
} else {
list = tmp;
}
} else {
printf("Error!");
}
return list;
}
void viewList(elem *list) {
while (list) {
if (list -> next) printf("%d -> ", list -> data);
if (!list -> next) printf ("%d\n");
list = list -> next;
}
}
int main() {
elem *List = NULL;
int Num;
scanf("%d", &Num);
while (Num) {
List = CreateList(List, Num);
scanf("%d", &Num);
}
}