Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create solu.cpp #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions DataStructures/Trees/Binary Search Tree : Insertion/solu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@


/*
Node is defined as

class Node {
public:
int data;
Node *left;
Node *right;
Node(int d) {
data = d;
left = NULL;
right = NULL;
}
};

*/

Node * insert(Node * root, int data) {
Node* temp=new Node(data);
Node* point=root;


if(root==NULL)
return temp;
while(true)
{
if(point->data>data)
{if(point->left==NULL)
{
point->left=temp;
break;
}
else
point=point->left;
}
else if(point->data<data)
{ if(point->right==NULL)
{
point->right=temp;
break;
}
else
point=point->right;
}
}



return root;
}