From cb7b64cd6ceb43c89dd4c64e7cbd5885c9e496e6 Mon Sep 17 00:00:00 2001 From: prakash Date: Sat, 13 Oct 2018 23:12:14 +0530 Subject: [PATCH 1/2] insertion and searching on BST --- Tree/binarySearchTreePrakash.c | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Tree/binarySearchTreePrakash.c diff --git a/Tree/binarySearchTreePrakash.c b/Tree/binarySearchTreePrakash.c new file mode 100644 index 0000000..5fe202e --- /dev/null +++ b/Tree/binarySearchTreePrakash.c @@ -0,0 +1,56 @@ +#include +#include +struct Node{ + int data; + struct Node* left; + struct Node* right; +}; +struct Node* Insert(struct Node* root,int data) +{ + if(root == NULL) + { + struct Node* temp = (struct Node*)malloc(sizeof(struct Node)); + (*temp).data = data; + (*temp).left = NULL; + (*temp).right = NULL; + root = temp; + } + else if(data <= (*root).data) + { + (*root).left = Insert((*root).left,data); + } + else if(data >= (*root).data) + { + (*root).right = Insert((*root).right,data); + } + return root; +} +bool search(struct Node* root,int data) +{ + if(root == NULL) + return false; + else if((*root).data == data) + return true; + else if(data <= (*root).data) + return search((*root).left,data); + else + return search((*root).right,data); +} +int main() +{ + struct Node* root = NULL; + root = Insert(root,15); + root = Insert(root,10); + root = Insert(root,20); + root = Insert(root,25); + root = Insert(root,8); + root = Insert(root,12); + int x; + printf("Enter no. to search\n"); + scanf("%d",&x); + if(search(root,x)) + printf("found\n"); + else + printf("not found\n"); + return 0; +} \ No newline at end of file From 0c4c5628a4a50fb4852e76c0a43877b85d6e8bf3 Mon Sep 17 00:00:00 2001 From: prakash Date: Sat, 13 Oct 2018 23:16:35 +0530 Subject: [PATCH 2/2] insertion and searching in BST --- Tree/{binarySearchTreePrakash.c => BinarySearchTreePrakash.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tree/{binarySearchTreePrakash.c => BinarySearchTreePrakash.cpp} (100%) diff --git a/Tree/binarySearchTreePrakash.c b/Tree/BinarySearchTreePrakash.cpp similarity index 100% rename from Tree/binarySearchTreePrakash.c rename to Tree/BinarySearchTreePrakash.cpp