From 085ead6a5dac89383d020818f1e625e624c616d2 Mon Sep 17 00:00:00 2001 From: Looser001 <72217767+Looser001@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:18:32 +0530 Subject: [PATCH] Create solu.cpp --- .../Binary Search Tree : Insertion/solu.cpp | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 DataStructures/Trees/Binary Search Tree : Insertion/solu.cpp diff --git a/DataStructures/Trees/Binary Search Tree : Insertion/solu.cpp b/DataStructures/Trees/Binary Search Tree : Insertion/solu.cpp new file mode 100644 index 0000000..a0bad9d --- /dev/null +++ b/DataStructures/Trees/Binary Search Tree : Insertion/solu.cpp @@ -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->dataright==NULL) + { + point->right=temp; + break; + } + else + point=point->right; + } + } + + + + return root; + } +