ROSS
avl_tree.h
Go to the documentation of this file.
1 #include <ross.h>
2 
3 /* Copied and modified from http://pine.cs.yale.edu/pinewiki/C/AvlTree google cache */
4 
5 /* implementation of an AVL tree with explicit heights */
6 
7 struct avlNode {
8  struct avlNode *child[2]; /* left and right */
10  int height;
11  struct avlNode *next; /* for ROSS weird linked-list memory */
12 };
13 
14 /* empty avl tree is just a null pointer */
15 
16 #define AVL_EMPTY (0)
17 
18 /* free a tree */
19 void avlDestroy(AvlTree t);
20 
21 /* return the height of a tree */
22 int avlGetHeight(AvlTree t);
23 
24 /* return nonzero if key is present in tree */
25 int avlSearch(AvlTree t, tw_event *key);
26 
27 /* insert a new element into a tree */
28 /* note *t is actual tree */
29 void avlInsert(AvlTree *t, tw_event *key);
30 
31 /* run sanity checks on tree (for debugging) */
32 /* assert will fail if heights are wrong */
33 void avlSanityCheck(AvlTree t);
34 
35 /* print all keys of the tree in order */
36 void avlPrintKeys(AvlTree t);
37 
38 /* delete and return minimum value in a tree */
40 
42 
43 AvlTree avl_alloc(void);
44 
45 void avl_free(AvlTree t);
tw_event * avlDelete(AvlTree *t, tw_event *key)
Definition: avl_tree.c:251
void avlPrintKeys(AvlTree t)
Definition: avl_tree.c:214
tw_event * key
Definition: avl_tree.h:9
int avlSearch(AvlTree t, tw_event *key)
Definition: avl_tree.c:40
Event Stucture.
Definition: ross-types.h:250
int avlGetHeight(AvlTree t)
Definition: avl_tree.c:28
tw_event * avlDeleteMin(AvlTree *t)
Definition: avl_tree.c:226
struct avlNode * next
Definition: avl_tree.h:11
AvlTree avl_alloc(void)
Definition: avl_tree.c:300
void avlDestroy(AvlTree t)
Definition: avl_tree.c:15
void avlSanityCheck(AvlTree t)
Definition: avl_tree.c:72
int height
Definition: avl_tree.h:10
struct avlNode * child[2]
Definition: avl_tree.h:8
void avlInsert(AvlTree *t, tw_event *key)
Definition: avl_tree.c:163
void avl_free(AvlTree t)
Definition: avl_tree.c:316