Lab8/avl_bag_lab8.c
/*

2. To test your function from (1), you need to create AVL trees (easy) as well as BSTs
   that are not AVL trees. Make a function 

   bool bag_insert_norot(bag_t *bag, bag_elem_t elem)
 
   which inserts an element into a BST without performing any rotations. Using this function,
   create BSTs that are not AVL trees.

   Show your TA that your is_avl_tree function returns true for AVL trees and returns false
   for non-AVL trees.
*/
2. To test your function from (1), you need to create AVL trees (easy) as well as BSTs
that are not AVL trees. Make a function



which inserts an element into a BST without performing any rotations. Using this function,
create BSTs that are not AVL trees.

Show your TA that your is_avl_tree function returns true for AVL trees and returns false
for non-AVL trees.
2 . To test your function from ( 1 ) you need to create AVL trees ( easy ) as well as BSTs that are not AVL trees . Make a function which inserts an element into a BST without performing any rotations . Using this function create BSTs that are not AVL trees . Show your TA that your is_avl_tree function returns true for AVL trees and returns false for non - AVL trees .
bool bag_insert_helper(avl_node_t *node, bag_elem_t elem, avl_node_t *new){
    if (*((int *)elem) < *((int *)(node->elem))) {
        if (!(node->left)){
            node->left = new;
            return true;
        }
        bag_insert_helper(node->left, elem, new);
    }
    else if (*((int *)elem) > *((int *)(node->elem))) {
            if (!(node->right)){
            node->right = new;
            return true;
        }
        bag_insert_helper(node->right, elem, new);
    }
    return false;
}
bool bag_insert_helper ( avl_node_t * node , bag_elem_t elem , avl_node_t * new ) { if ( * ( ( int * ) elem ) < * ( ( int * ) ( node -> elem ) ) ) { if ( ! ( node -> left ) ) { node -> left = new ; return true ; } bag_insert_helper ( node -> left , elem , new ) ; } else if ( * ( ( int * ) elem ) > * ( ( int * ) ( node -> elem ) ) ) { if ( ! ( node -> right ) ) { node -> right = new ; return true ; } bag_insert_helper ( node -> right , elem , new ) ; } return false ; }
2.
2 .
//printf("comparing %d %d\n", *((int *)elem), *((int *)(node->elem))); //printf("comparing %d %d\n", *((int *)elem), *((int *)(node->elem)));