Repositories » libk0
Clone URL:  
Pushed to one repository · View In Graph Contained in v0.1 and tip

Test program

Changeset 5207306d8e57

Parent 7f13c12583ab

by Rup Palchowdhury

Changes to one file · Browse files at 5207306d8e57 Showing diff from parent 7f13c12583ab Diff from another changeset...

Change 1 of 1 Show Entire File test.c Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@@ -0,0 +1,74 @@
+#include <stdio.h> +#include "ktree.h" +#include "klist.h" +#include "khash.h" +#include "kpost.h" + +#define NUMNODES 10 + +int main(void) +{ + char s[NUMNODES][10] = {"f", "b", "g", "a", "d", + "i", "c", "e", "h", "h"}; + int i; + Node *lt, *n, *tmp; + TNode *t, *t_; + + /* hash table test */ + /* + const int NHASH = 5; + Node *htab[NHASH]; + for (i = 0; i < NHASH; i++) + htab[i] = NULL; + + for (i = 0; i < 9; i++) { + tmp = hlookup(htab, newnode(newpost(s[i], i)), 1, + hashpost, NHASH, postcmp); + } + + printhtab(htab, NHASH, printpost); + + tmp = hlookup(htab, newnode(newpost(s[0], 0)), 0, + hashpost, NHASH, postcmp); + + if (tmp != NULL) + printpost(tmp->data, "Found: %s %1.0f\n"); + else + printf("Not found\n"); + */ + + /* tree test */ + + t = NULL; + for (i = 0; i < NUMNODES; i++) + t = insert(t, newtnode((void *)newpost(s[i], 1)), + postcmp, post_match_handler); + printf("inorder:\n"); + applyinorder(t, printpost, "%s %d\n"); + printf("\n"); + printf("postorder:\n"); + applypostorder(t, printpost, "%s %d\n"); + + /* list test */ + + /* n = newnode((void *)newpost(s[1], 1)); */ + /* lt = newnode((void *)newpost(s[0], 0)); */ + /* for (i = 1; i < 3; i++) */ + /* lt = addfront(lt, newnode((void *)newpost(s[i], i))); */ + /* apply(lt, printpost, "%s %f\n"); */ + /* printf("\n"); */ + + /* addend(lt, newnode((void *)newpost(s[3], 3))); */ + /* apply(lt, printpost, "%s %f\n"); */ + /* printf("\n"); */ + + /* tmp = lookup(lt, n, postcmp); */ + /* printpost(tmp->data, "%s %f\n"); */ + /* printf("\n"); */ + + /* delnode(lt, n, postcmp, freepost); */ + /* apply(lt, printpost, "%s %f\n"); */ + /* printf("\n"); */ + + return 0; +}