0% found this document useful (0 votes)
27 views30 pages

BST

Uploaded by

fairykomal993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views30 pages

BST

Uploaded by

fairykomal993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Algorithm to create bst

• struct node{
int data;
struct node* left;
struct node* right;};
struct node* createNode(value)
newNode -> data = value;
newNode -> left = NULL;
newNode -> right = NULL;
return newNode;
Algorithm to insert in bst
struct node* insert(struct node* root, int data){
if (root == NULL)
return createNode(data);
if (data < root -> data)
root -> left = insert(root -> left, data);
else if (data > root -> data)
root -> right = insert(root -> right, data);
return root;
}

You might also like