Skip to content
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
24 changes: 24 additions & 0 deletions Binary search tree/Merge two BST 's
Original file line number Diff line number Diff line change
@@ -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<int>&v){
if(root==NULL)
{
return ;
}
solve(root->left,v);
v.push_back(root->data);
solve(root->right,v);
}
vector<int> merge(Node *root1, Node *root2)
{
//Your code here
vector<int>ans;
solve(root1,ans);
solve(root2,ans);
sort(ans.begin(),ans.end());
return ans;
}
};