C
x
38
1
2
3
4
struct node{
5
int value;
6
struct node *next;
7
};
8
9
typedef struct node node_t;
10
11
void push(node_t *h, int val){
12
13
//copy value head
14
node_t *copy;
15
copy = h;
16
17
//reach to last node
18
while(copy->next != NULL)
19
copy = copy->next;
20
21
//make new node and value "val"
22
copy->next = malloc(sizeof(node_t));
23
copy->next->next = NULL;
24
copy->next->value = val;
25
}
26
27
int main(){
28
29
node_t h;
30
31
h.next = NULL;
32
push(&h, 100);
33
push(&h, 200);
34
push(&h, 300);
35
36
printf("%d", h.next->value);
37
return EXIT_SUCCESS;
38
}
$ gcc prog.c -Wall -Wextra -std=gnu11
Start
100
0
Finish