Binary Search Tree : Insertion

  • + 0 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; }