-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_tree_to_dll.cpp
More file actions
94 lines (52 loc) · 1.14 KB
/
binary_tree_to_dll.cpp
File metadata and controls
94 lines (52 loc) · 1.14 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "binary_tree_essentials.cpp"
void binary_tree_to_dll(struct bnode*root,struct bnode**head){
if(root==NULL){
return ;
}
else{
static struct bnode*temp=NULL;
binary_tree_to_dll(root->left,head);
if(temp==NULL){
temp=root;
*head=temp;
}
else{
temp->right=root;
root->left=temp;
temp=root;
}
binary_tree_to_dll(root->right,head);
}
}
void print_list(struct bnode*root){
while(root->right){
cout<<root->data<<" ";
root=root->right;
}
}
int i=0;
void store_inorder(struct bnode*root , int (&array)[100]){
if(root==NULL){
return;
}
store_inorder(root->left,array);
array[i++]=root->data;
store_inorder(root->right,array);
}
int main(){
struct bnode *root = newNode(10);
root->left = newNode(12);
root->right = newNode(15);
root->left->left = newNode(25);
root->left->right = newNode(30);
root->right->left = newNode(36);
// inorder(root);
cout<<endl;
int array[100];
store_inorder(root,array);
print_array(array,i);
struct bnode*head=NULL;
// binary_tree_to_dll(root,&head);
// print_list(head);
return 1;
}