-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtst.h
31 lines (23 loc) · 987 Bytes
/
tst.h
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
/* This is a library module supporting Ternary Search Trees (TSTs).
It allows the user to store strings and associated values.
The characters are stored in nodes.
Each node has 3 children: smaller (left), equal (middle) and larger (right).
This avoids using a large number of NULL pointers as with an R-way Trie
*/
struct tst;
typedef struct tst tst;
struct node;
typedef struct node node;
// Create a new empty TST and return a pointer to it.
tst *newTst();
// Insert a string into a TST. It is illegal to inser a string that already exists.
void insertString(tst *t, int x, char *c);
// Search for a string and return its associated value if found, or -1 if not found.
int search(tst *t, char *c);
// Get a pointer to a node. NULL if not found.
node *findNode(tst *t, char *c);
// Change the x value of a given node.
void amend(node *n, int x);
// Remove a string by setting its value to NULL. If possible also remove any
// unused nodes.
void removeString(tst *t, char *c);