view src/trie_sedgewick_test.c @ 16:5d8158ad2d61

sedgewick trie
author Eris Caffee <discordia@eldalin.com>
date Thu, 04 Oct 2012 23:07:48 -0500
parents
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "trie_sedgewick.h"
6 int main(int argc, char ** argv)
7 {
8 struct trie * trie = trie_new();
9 if (NULL == trie)
10 {
11 fprintf(stderr, "trie_new failed\n");
12 exit(EXIT_FAILURE);
13 }
15 char * words[] =
16 {
17 "she", "sells", "sea", "shells", "by", "the", "sea", "shore", NULL,
18 };
20 printf("Loading trie\n");
21 char ** w = words;
22 while (*w)
23 {
24 if (NULL == trie_put(trie, *w, *w))
25 {
26 fprintf(stderr, "trie_put failed on %s\n", *w);
27 exit(EXIT_FAILURE);
28 }
29 w++;
30 }
32 printf("Reading trie\n");
33 w = words;
34 while (*w)
35 {
36 char * value;
37 if (NULL == (value = trie_get(trie, *w)))
38 {
39 fprintf(stderr, "trie_get failed on %s\n", *w);
40 exit(EXIT_FAILURE);
41 }
42 printf("%s\n", value);
43 w++;
44 }
46 exit(EXIT_SUCCESS);
47 }