I tried a lot to sort through the network, but could get any help. Everywhere it looks like adding a node to the binary search tree.
Question: querying the algorithm and code snippet to add node to the binary tree . (or give me the correct URL)
Assumption: In my understanding, is the binary tree and the binary search tree different? Correct me if I am wrong.
(query: if you are writing a piece of code, use the correct variable name, which helps in understanding)
For example: Binary Tree
5 7 3 x 1 x 2 x 3
5 7 3 x1 x2 x3
Binary Search Tree 5 7 3 2 4 6
5 3 7 2 4 6 insert(int key, struct node **root) { if( NULL == *root )` { *root = (struct node*) malloc( sizeof( struct node ) );` (*root)->data = key; (*root)->left = NULL; (*root)->right = NULL; } else if(key < (*root)->data) { insert( key, &(*root)->left ); } else if(key > (*root)->data) { insert( key, &(*root)->right ); } }
Raa
source share