89 return ((
t_tree*)d)->count;
106 if (t->
find(t, data) != NULL) {
107 LOG_WARN(
"TREES",
"%s: Key not present\n");
115 new->lchild =
new->rchild = NULL;
118 if (t->
root == NULL) {
125 while (cur != NULL) {
130 res = t->
cmpr(new->key, cur->key);
141 res = t->
cmpr(new->key, parent->
key);
162 while (cur != NULL) {
170 }
else if (res ==
eLESS) {
196 while (cur->
lchild != NULL) {
218 while (cur->
rchild != NULL) {
240 if (cur->
lchild == NULL) {
262 if (cur->
rchild == NULL) {
288 res = t->
cmpr(data, cur->key);
303 if (cur->lchild != NULL) {
304 pred = t->
max(cur->lchild);
311 if (cur == NULL || pred == NULL) {
338 res = t->
cmpr(data, cur->key);
353 if (cur->rchild != NULL) {
354 succ = t->
min(cur->rchild);
361 if (cur == NULL || succ == NULL) {
424 else if (cur == prv->
lchild) {
482 while (q->
empty(q) !=
true) {
491 if (cur->
lchild != NULL) {
495 if (cur->
rchild != NULL) {
533 while (q->
empty(q) !=
true) {
538 if (cur->
lchild != NULL) {
542 if (cur->
rchild != NULL) {
547 t->
free(cur->
key, __FILE__, __LINE__);
573 printf(
"%s: %d nodes postorder traversal\n", t->
name, t->
count);
582 if (cur->
rchild != NULL) {
593 tmp = (s->
empty(s) !=
true)? s->
peek(s, 0): NULL;
609 }
while (s->
empty(s) !=
true);
633 printf(
"%s: %d nodes preorder traversal\n", t->
name, t->
count);
640 while (s->
empty(s) !=
true) {
647 if (cur->
lchild != NULL) {
650 if (cur->
rchild != NULL) {
676 printf(
"%s: %d nodes inorder traversal\n", t->
name, t->
count);
681 while (s->
empty(s) !=
true || cur != NULL) {
683 while (cur != NULL) {
719 printf(
"%s: %d nodes lvl based print \n", t->
name,t->
count);
726 while (q->
empty(q) !=
true) {
727 printf(
" %d :",level);
739 if (cur->
lchild != NULL) {
745 if (cur->
rchild != NULL) {
776 height = (lh >rh)? lh: rh;
894 if (t->
find(t, data) != NULL) {
895 LOG_WARN(
"TREES",
"%s: Key not present\n");
903 new->lchild =
new->rchild = NULL;
907 if (t->
root == NULL) {
918 while (cur != NULL) {
923 res = t->
cmpr(new->key, cur->key);
937 res = t->
cmpr(new->key, parent->
key);
945 while (s->
empty(s) !=
true) {
1020 else if (cur == prv->
lchild) {
1054 while (s->
empty(s) !=
true) {
void init_data_params(t_dparams *, e_data_types)
Called to initalize data params for default data types Else for custom data types the data params str...
#define LOG_WARN(mod, fmt, args...)
#define free_mem(mem_addr)
#define get_mem(nmemb, size)
t_gen create_queue(char *name, int max_size, e_queuetype qtype, t_dparams *prm)
Destroy queue instance
Contains declations of queue types, operations and structure.
@ eLL_QUEUE_CIRC
Link List Based Queue.
t_gen create_stack(char *name, int max_size, e_stacktype stype, t_dparams *prm)
Create an instance of stack
Contains declations of stack types, operations and structure.
@ eLL_STACK
LinkList based Stack.
f_cmpr cmpr
Routine used for comparing two given elems of said type.
f_swap swap
Routine used for swaping two elemnts of goven data.
f_free free
Routine used for freeing elements of said data.
f_print print_data
Routine used for printing elem data.
f_vgen destroy
routine to destroy stack contents
f_gen2 push
stack operations
f_empty empty
routine to check if stack is empty
f_genidx peek
routine to peek elements in stack
f_gen pop
routine to pop element into stack
f_len len
routine to get length queue
f_gen deq
routine to pop elements out of queue
f_destroy destroy
routine to detroy queue instance
f_empty empty
routine to check if queue empty
f_ins enq
routine to push elements to queue
struct tree_node * rchild
Pointer to node right child.
t_gen key
Pointer to node key.
struct tree_node * lchild
Pointer to node left child.
f_gen min
routine to get minm element in tree
f_find find
routine to find element in tree
f_len height
routine to get height of tree
f_gen2 pred
routine to get predecessor to given node
f_ins insert
routine to insert element in tree
f_len node_count
routine to get total nodes in tree
f_print print
routine to print tree level by level
e_treetype type
Tree Type.
char * name
Tree instance name.
f_print inorder
routine to print inorder traversal of tree
f_gen max
routine to get maxm element in tree
f_destroy destroy
routine to destroy the tree instance
f_print preorder
routine to print preorder traversal of tree
t_gen root
Root node of the tree.
f_gen2 succ
routine to get successor to given node
f_del del
routine to delete element in tree
int count
Tree node count.
f_print postorder
routine to print postorder traversal of tree
void tree_rotate_right(t_gen n)
rotate subtree right
f_ins tree_insert[]
Look Up function ptrs for inserting elem to tree.
t_gen create_tree(char *name, e_treetype ttype, t_dparams *prm)
Create an instance of tree
int tree_slope(t_gen n)
get slope of node subtree
t_gen tree_node_successor(t_gen, t_gen)
find the successor of a given node in tree
void tree_preorder(t_gen)
preorder traverse tree
t_gen tree_get_min_rcrs(t_gen root)
get min node in tree recursively
void tree_inorder(t_gen)
inorder traverse tree
t_gen tree_get_min(t_gen)
get min node in tree
t_gen tree_delete_node_bst(t_gen, t_gen)
Delete a node in a bst tree
f_len tree_height[]
Look Up function ptrs for getting height of tree.
int tree_height_bst(t_gen n)
get height of bst
t_gen tree_delete_node_avl(t_gen, t_gen)
Delete a node in an avl tree
void print_tree(t_gen)
print tree info level by level
f_del tree_del[]
Look Up function ptrs for deleting elem to tree.
void tree_rotate_left(t_gen n)
rotate subtree left
void tree_rebalance(t_gen n)
rebalance subtree
t_gen tree_get_max_rcrs(t_gen root)
get max node in tree recursively
int tree_height_avl(t_gen n)
get height of avl subtree
void tree_insert_node_avl(t_gen, t_gen)
Add element to an avl tree
void tree_postorder(t_gen)
postorder traverse tree
t_gen tree_get_max(t_gen)
get max node in tree
t_gen tree_node_predecessor(t_gen, t_gen)
find the predecessor of a given node in tree
void tree_insert_node_bst(t_gen, t_gen)
Add element to a bst tree
void destroy_tree(t_gen)
Destroy the instance of the tree
t_gen tree_find_node(t_gen, t_gen)
find an element in tree
int tree_node_count(t_gen n)
get_num_nodes in tree;
Contains declations of tree types, operations and structure.
e_treetype
Types of trees.
int(* f_len)(t_gen)
fn type of get len function
void * t_gen
Base Data type used for all data structure and data elements.
f_vgen2 f_ins
fn type of insert elem function
e_cmpr
Custom Compare function return type.
f_gen2 f_del
fn type of delete elem function