-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTree2.cpp
159 lines (135 loc) · 3.95 KB
/
Tree2.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// // #include "Tree.hpp"
// // bool Tree::insert(char data){
// // Tree_Node* curr = root;
// // Tree_Node* prev = NULL;
// // bool inserted = false;
// // while(!inserted){
// // if(curr == NULL){
// // curr = new Tree_Node(prev, data);
// // inserted = true;
// // }
// // else{
// // if(curr->data > data){
// // prev = curr;
// // curr = left;
// // }
// // else{
// // prev = curr;
// // curr = right;
// // }
// // }
// // }
// // return inserted;
// // }
// // Tree_Node* Tree::search(char data){
// // Tree_Node* curr = root;
// // while(curr){
// // if(curr->data == data)
// // {
// // return curr;
// // }
// // else if(curr->data > data){
// // curr = left;
// // }
// // else{
// // curr = right;
// // }
// // }
// // return curr;
// // }
// // void Tree::print_sorted(){
// // Tree_Node* curr = left_most();
// // Tree_Node* prev = curr->parent;
// // printf("Smallest\n%c\n", curr->data)
// // while(curr != root){
// // if(curr->left != NULL){
// // printf("%c\n", curr->left->data);
// // }
// // if(curr->right != NULL){
// // printf("%c\n", curr->right->data);
// // }
// // else{
// // if(curr->data > data){
// // prev = curr;
// // curr = left;
// // }
// // else{
// // prev = curr;
// // curr = right;
// // }
// // }
// // }
// // return inserted;
// // }
// // void Tree::_delete(){
// // }
// // Tree_Node* TREE::left_most(){
// // Tree_Node* curr = root;
// // Tree_Node* prev = NULL;
// // bool found = false;
// // while(!found){
// // if(curr->left != NULL){
// // prev = curr;
// // curr = left;
// // }
// // else if(curr->right != NULL){
// // prev = curr;
// // curr = right;
// // }
// // else{
// // found = true;
// // }
// // }
// // return curr;
// // }
// // Tree_Node* right_most(){
// // Tree_Node* curr = root;
// // Tree_Node* prev = NULL;
// // bool found = false;
// // while(!found){
// // if(curr->right != NULL){
// // prev = curr;
// // curr = right;
// // }
// // else if(curr->left != NULL){
// // prev = curr;
// // curr = left;
// // }
// // else{
// // found = true;
// // }
// // }
// // return curr;
// // }
// // Tree::Tree(){
// // root = new Tree_Node;
// // }
// // Tree::~Tree(){
// // _delete();
// // }
// Tree_Node* Tree::left_most(Tree_Node* Root){
// Tree_Node* location = NULL;
// if(Root->left != NULL){//if there is a subtree on the left
// location = left_most(Root->left);//search the subtree on the left
// }
// else if(Root->right != NULL){//if there is a subtree on the right
// location = left_most(Root->right);//search the subtree on the right
// }
// else{//if there are no more subtrees
// location = Root;//the node has been found
// }
// return location;
// }
// Tree_Node* right_most(Tree_Node* Root){
// Tree_Node* location = NULL;
// if(Root->right != NULL){//if there is a subtree on the right
// location = right_most(Root->right);//search the subtree on the right
// }
// else if(Root->left != NULL){//if there is a subtree on the left
// location = right_most(Root->left);//search the subtree on the left
// }
// else{//if there are no more subtrees
// location = Root;//the node has been found
// }
// return location;
// }