Skip to content
Closed
Changes from 2 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
56 changes: 34 additions & 22 deletions data_structures/binary_search_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ void BFT(node *n) {
}
}

/*
Prints the preorder traversal starting from the node n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow doxygen documentation for documenting functions.
https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md

Prints root - leftChild - rightChild
*/
void Pre(node *n) {
if (n != NULL) {
std::cout << n->val << " ";
Expand All @@ -106,6 +110,10 @@ void Pre(node *n) {
}
}

/*
Prints the inorder traversal starting from the node n
Prints leftChild - root - rightChild
*/
void In(node *n) {
if (n != NULL) {
In(n->left);
Expand All @@ -114,6 +122,10 @@ void In(node *n) {
}
}

/*
Prints the postorder traversal starting from the node n
Prints left - rightChild - root
*/
void Post(node *n) {
if (n != NULL) {
Post(n->left);
Expand Down Expand Up @@ -145,28 +157,28 @@ int main() {
std::cin >> ch;
int x;
switch (ch) {
case 1:
std::cout << "\nEnter the value to be Inserted : ";
std::cin >> x;
Insert(root, x);
break;
case 2:
std::cout << "\nEnter the value to be Deleted : ";
std::cin >> x;
Remove(root, root, x);
break;
case 3:
BFT(root);
break;
case 4:
Pre(root);
break;
case 5:
In(root);
break;
case 6:
Post(root);
break;
case 1:
std::cout << "\nEnter the value to be Inserted : ";
std::cin >> x;
Insert(root, x);
break;
case 2:
std::cout << "\nEnter the value to be Deleted : ";
std::cin >> x;
Remove(root, root, x);
break;
case 3:
BFT(root);
break;
case 4:
Pre(root);
break;
case 5:
In(root);
break;
case 6:
Post(root);
break;
}
} while (ch != 0);

Expand Down