You are viewing a single comment's thread. Return to all comments →
"c language" struct node* newNode(int data) { struct node* node=(struct node*)malloc(sizeof(struct node)); node->data=data; node->left=NULL; node->right=NULL; return(node); }
struct node* insert(struct node* root, int data) { if(root==NULL) { return(newNode(data)); } else { struct node* cur; if(data<=root->data) { cur=insert(root->left,data); root->left=cur; } else { cur=insert(root->right,data); root->right=cur; } } return root; }
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Insertion
You are viewing a single comment's thread. Return to all comments →
"c language" struct node* newNode(int data) { struct node* node=(struct node*)malloc(sizeof(struct node)); node->data=data; node->left=NULL; node->right=NULL; return(node); }
struct node* insert(struct node* root, int data) { if(root==NULL) {
return(newNode(data)); } else { struct node* cur; if(data<=root->data) { cur=insert(root->left,data); root->left=cur; } else { cur=insert(root->right,data); root->right=cur; } } return root; }