From f7145d49ebb27c9c488970959715b71a7cc15a01 Mon Sep 17 00:00:00 2001 From: Aditya Raj <103483702+adityaraj6902@users.noreply.github.com> Date: Sat, 29 Oct 2022 15:16:10 +0530 Subject: [PATCH] Create Merge two BST 's --- Binary search tree/Merge two BST 's | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Binary search tree/Merge two BST 's diff --git a/Binary search tree/Merge two BST 's b/Binary search tree/Merge two BST 's new file mode 100644 index 0000000..c68d7ff --- /dev/null +++ b/Binary search tree/Merge two BST 's @@ -0,0 +1,24 @@ +class Solution +{ + public: + //Function to return a list of integers denoting the node + //values of both the BST in a sorted order. + void solve (Node *root,vector&v){ + if(root==NULL) + { + return ; + } + solve(root->left,v); + v.push_back(root->data); + solve(root->right,v); + } + vector merge(Node *root1, Node *root2) + { + //Your code here + vectorans; + solve(root1,ans); + solve(root2,ans); + sort(ans.begin(),ans.end()); + return ans; + } +};