-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
50 lines (35 loc) · 749 Bytes
/
Copy pathlist.c
File metadata and controls
50 lines (35 loc) · 749 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
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int value;
struct node *addr;
}node;
int printlist(node *root);
int main(void){
node *root = malloc(sizeof(node));
root ->value = 56;
root ->addr = NULL;
node *p = malloc(sizeof(node));
p -> value = 22;
p -> addr = root;
root = p;
node *s = malloc(sizeof(node));
s -> value = 78;
s -> addr = root;
root = s;
printlist(root);
free(p->addr);
free(p);
free(root);
}
int printlist(node *root){
if (root->addr == NULL){
return 0;
}
while (root->addr != NULL){
printf("value: %i\n",root->value);
root = root->addr;
}
printf("value: %i\n",root->value);
return 1;
}