23 int IntComp(
const void* a,
const void* b) {
24 if( *(
int*)a > *(
int*)b)
return(1);
25 if( *(
int*)a < *(
int*)b)
return(-1);
30 printf(
"%i",*(
int*)a);
51 printf(
"choose one of the following:\n");
52 printf(
"(1) add to tree\n(2) delete from tree\n(3) query\n");
53 printf(
"(4) find predecessor\n(5) find successor\n(6) enumerate\n");
54 printf(
"(7) print tree\n(8) quit\n");
55 do option=fgetc(stdin);
while(-1 != option && isspace(option));
61 printf(
"type key for new node\n");
63 newInt=(
int*) malloc(
sizeof(
int));
71 printf(
"type key of node to remove\n");
74 else printf(
"key not found in tree, no action taken\n");
80 printf(
"type key of node to query for\n");
83 printf(
"data found in tree at location %i\n",(
int)newNode);
85 printf(
"data not in tree\n");
91 printf(
"type key of node to find predecessor of\n");
95 if(tree->
nil == newNode) {
96 printf(
"there is no predecessor for that node (it is a minimum)\n");
98 printf(
"predecessor has key %i\n",*(
int*)newNode->
key);
101 printf(
"data not in tree\n");
107 printf(
"type key of node to find successor of\n");
111 if(tree->
nil == newNode) {
112 printf(
"there is no successor for that node (it is a maximum)\n");
114 printf(
"successor has key %i\n",*(
int*)newNode->
key);
117 printf(
"data not in tree\n");
123 printf(
"type low and high keys to see all keys between them\n");
124 scanf(
"%i %i",&newKey,&newKey2);
126 while ( (newNode =
StackPop(enumResult)) ) {
145 printf(
"Invalid input; Please try again.\n");
int IntComp(const void *a, const void *b)
rb_red_blk_node * RBTreeInsert(rb_red_blk_tree *tree, void *key, void *info)
void IntPrint(const void *a)
void(* PrintKey)(const void *a)
rb_red_blk_node * TreeSuccessor(rb_red_blk_tree *tree, rb_red_blk_node *x)
void RBDelete(rb_red_blk_tree *tree, rb_red_blk_node *z)
stk_stack * RBEnumerate(rb_red_blk_tree *tree, void *low, void *high)
DATA_TYPE StackPop(stk_stack *theStack)
rb_red_blk_tree * RBTreeCreate(int(*CompFunc)(const void *, const void *), void(*DestFunc)(void *), void(*InfoDestFunc)(void *), void(*PrintFunc)(const void *), void(*PrintInfo)(void *))
void RBTreePrint(rb_red_blk_tree *tree)
rb_red_blk_node * TreePredecessor(rb_red_blk_tree *tree, rb_red_blk_node *x)
void RBTreeDestroy(rb_red_blk_tree *tree)
rb_red_blk_node * RBExactQuery(rb_red_blk_tree *tree, void *q)
int main(int argc, char **argv)