binarytree/binarytree.c
/*****************************************************************************/
/* Inserts node with a given value */
Inserts node with a given value
Inserts node with a given value
void insertVal(Tree *tree, int value){
    Node **node=findNodeByVal(&(tree->root), value); 
    if (!(*node)){
        (*node) = (Node *) malloc(sizeof(Node));
        (*node)->id = globalid++;
        (*node)->val = value;
        (*node)->left = NULL;
        (*node)->right = NULL;
        if(DEBUG==1) printf("Checkpoint: Function %s, line %d\n", __func__, __LINE__);
        printf("New node created with ID %i and value %i.\n", (*node)->id, (*node)->val);
    }
    else { 
        printf("A node with that value (%i) already exists with id %i. "
                "No new node created.\n", (*node)->val, (*node)->id);
    }
}
void insertVal ( Tree * tree , int value ) { Node * * node = findNodeByVal ( & ( tree -> root ) , value ) ; if ( ! ( * node ) ) { ( * node ) = ( Node * ) malloc ( sizeof ( Node ) ) ; ( * node ) -> id = globalid ++ ; ( * node ) -> val = value ; ( * node ) -> left = NULL ; ( * node ) -> right = NULL ; if ( DEBUG == 1 ) printf ( " \n " , __func__ , __LINE__ ) ; printf ( " \n " , ( * node ) -> id , ( * node ) -> val ) ; } else { printf ( " " " \n " , ( * node ) -> val , ( * node ) -> id ) ; } }
Inserts node with a given value
Inserts node with a given value
/* Alias for traversal */ /* Possible only if value already exists in the tree. */ /* Throw warning and do nothing. */