diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-07-13 12:22:26 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-07-13 12:25:30 -0400 |
commit | 341263ccecb5b112703633dedcd61970c43f72ae (patch) | |
tree | 2bdcb90836d780c28273633dc71983b5c7d22c53 | |
parent | 94894e7294320eb724141242c33a264e93386360 (diff) |
Add node from old code v1@9f14600
-rw-r--r-- | node.c | 43 | ||||
-rw-r--r-- | node.h | 18 |
2 files changed, 61 insertions, 0 deletions
@@ -0,0 +1,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; +} @@ -0,0 +1,18 @@ +#ifndef NODE_H +#define NODE_H + +/* Linked list */ + +typedef struct node_s { + char *name; + struct node_s *next; +} node_t; + +/*constructor*/ +node_t* mknode(char *); + +/* helpers */ +node_t* search(node_t*, char *); +node_t* insert(node_t*, char*); + +#endif |