-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
57 lines (48 loc) · 890 Bytes
/
code.c
File metadata and controls
57 lines (48 loc) · 890 Bytes
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
void putchar(char c);
typedef struct Node
{
int value;
void *next;
} Node;
typedef struct LinkedList
{
Node *first;
Node *last;
} LinkedList;
Node *malloc(int size);
void free(Node *ptr);
int push(LinkedList *list, int value)
{
Node *node = malloc(12);
node->value = value;
if (list->first == 0)
{
list->first = node;
list->last = node;
return 0;
}
list->last->next = node;
list->last = node;
return 0;
}
void test() {
LinkedList list;
list.first = (void*)0;
list.last = (void*)0;
for (int i = 0; i < 10; i = i + 1) {
push(&list, i);
}
Node* current = list.first;
while (current) {
putchar(current->value+ '0');
putchar(10);
Node* next = current->next;
free(current);
current = next;
}
}
int main()
{
test();
return 0;
}