-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.c
More file actions
36 lines (30 loc) · 739 Bytes
/
Copy pathnode.c
File metadata and controls
36 lines (30 loc) · 739 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
#include "stdio.h"
#include "stdlib.h"
#include "node.h"
node_t initNode(int vertex) {
node_t newNode = malloc(sizeof (node_s));
newNode->_vertex = vertex;
newNode->_next = NULL;
return newNode;
}
void addNode(node_t *root, int vertex) {
if (*root == NULL) *root = initNode(vertex);
else {
node_t tmp = *root;
while (tmp->_next != NULL) {
tmp = tmp->_next;
}
tmp->_next = initNode(vertex);
}
}
void traverseNode(node_t *root) {
node_t tmp = *root;
if (tmp != NULL) {
printf("%d", tmp->_vertex);
while (tmp->_next != NULL) {
tmp = tmp->_next;
printf(" -> %d", tmp->_vertex);
}
printf("\n");
}
}