-
Notifications
You must be signed in to change notification settings - Fork 40
/
28 August "Problem of the Day" Answer
48 lines (39 loc) · 1.09 KB
/
28 August "Problem of the Day" Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
GeeksforGeeks
The Question is :- "Binary Tree to DLL"
Answer :-
class Solution
{
public:
//Function to convert binary tree to doubly linked list and return it.
void inOrder(Node* root code changed.
root chhane developed
rooot instial command root etc. root,vector<int> &v){
if(root==NULL){
return;
}
inOrder(root->left,v);
v.push_back(root->data);
inOrder(root->right,v);
}
Node * bToDLL(Node *root)
{
// your code here
vector<int> a;
inOrder(root,a);
Node* head=newNode(a[0]);
head->left=NULL;
Node* curr=head;
Node* x;
for(int i=1;i<a.size();i++){
x=newNode(a[i]);
x->left=curr;
curr->right=x;
curr=x;
}
x->right=NULL;
return head;
}
};
Hope you understand the answer, and complete it.
Stay Connected for daily Problem of the Day answers.
Thank you All!