blob: c52b1015bdd95713f138a7b2be8d0c975fb5a9a6 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "node.h"
/*constructor*/
node_t* mknode(str)
char *str;
{
node_t *p = malloc(sizeof(node_t));
assert(p);
p->name = strdup(str);
p->next = NULL;
return p;
}
/* helpers */
node_t* search(root, str)
node_t *root;
char *str;
{
node_t *p = root;
while (p) {
if (!strcmp(p->name, str)) {
return p;
}
p = p->next;
}
return NULL;
}
node_t* insert(root, str) /*TODO change to accept double pointer*/
node_t *root;
char * str;
{
node_t *p = mknode( str );
p->next = root;
return p;
}
|