Skip to content

Commit 8b0f2fe

Browse files
Radhika ShahRadhika Shah
authored andcommitted
Adding comments for tree traversal
1 parent c2adc3b commit 8b0f2fe

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

data_structures/binary_search_tree.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ void BFT(node *n) {
9898
}
9999
}
100100

101+
/*
102+
Prints the preorder traversal starting from the node n
103+
*/
101104
void Pre(node *n) {
102105
if (n != NULL) {
103106
std::cout << n->val << " ";
@@ -106,6 +109,9 @@ void Pre(node *n) {
106109
}
107110
}
108111

112+
/*
113+
Prints the inorder traversal starting from the node n
114+
*/
109115
void In(node *n) {
110116
if (n != NULL) {
111117
In(n->left);
@@ -114,6 +120,9 @@ void In(node *n) {
114120
}
115121
}
116122

123+
/*
124+
Prints the postorder traversal starting from the node n
125+
*/
117126
void Post(node *n) {
118127
if (n != NULL) {
119128
Post(n->left);
@@ -145,28 +154,28 @@ int main() {
145154
std::cin >> ch;
146155
int x;
147156
switch (ch) {
148-
case 1:
149-
std::cout << "\nEnter the value to be Inserted : ";
150-
std::cin >> x;
151-
Insert(root, x);
152-
break;
153-
case 2:
154-
std::cout << "\nEnter the value to be Deleted : ";
155-
std::cin >> x;
156-
Remove(root, root, x);
157-
break;
158-
case 3:
159-
BFT(root);
160-
break;
161-
case 4:
162-
Pre(root);
163-
break;
164-
case 5:
165-
In(root);
166-
break;
167-
case 6:
168-
Post(root);
169-
break;
157+
case 1:
158+
std::cout << "\nEnter the value to be Inserted : ";
159+
std::cin >> x;
160+
Insert(root, x);
161+
break;
162+
case 2:
163+
std::cout << "\nEnter the value to be Deleted : ";
164+
std::cin >> x;
165+
Remove(root, root, x);
166+
break;
167+
case 3:
168+
BFT(root);
169+
break;
170+
case 4:
171+
Pre(root);
172+
break;
173+
case 5:
174+
In(root);
175+
break;
176+
case 6:
177+
Post(root);
178+
break;
170179
}
171180
} while (ch != 0);
172181

0 commit comments

Comments
 (0)