view src/trie_test.c @ 12:d359966ed8de

Added trie
author Eris Caffee <discordia@eldalin.com>
date Mon, 01 Oct 2012 15:50:30 -0500
parents
children 7886d2da8cc4
line source
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "trie.h"
6 void print_val(char * key, void * data)
7 {
8 printf("%s\n", key);
9 }
11 int main(int argc, char ** argv)
12 {
13 struct trie * trie = trie_new();
15 char * words[] = { "hello", "interjection (used to express a greeting, answer a telephone, or attract attention.)",
16 "help", "to give or provide what is necessary to accomplish a task or satisfy a need.",
17 "helper", "a person or thing that helps or gives assistance, support, etc",
18 "helping", "the act of a person or thing that helps.",
19 "a", "indefinite article. Used before an initial consonant sound.",
20 "an", "indefinite article. the form of a before an initial vowel sound.",
21 "anna", "a female name",
22 "anne", "a female name",
23 "any", "one, a, an, or some; one or more without specification or identification",
24 "anyway", "in any case; anyhow; nonetheless; regardless",
25 "anyhow", "in any way whatever",
26 "anybody", "any person",
27 "Apple", "A computer manufacturer.",
28 "ABLE", "having necessary power, skill, resources, or qualifications",
29 NULL, NULL
30 };
31 int i = 0;
32 while (words[i])
33 {
34 trie_insert(trie, words[i], words[i+1]);
35 i += 2;
36 }
38 trie_dump(trie);
40 void * data = trie_find(trie, "any");
41 if (NULL == data)
42 printf("Failed to find 'any'\n");
43 else
44 printf("any: %s\n", (char *) data);
46 exit(EXIT_SUCCESS);
47 }