45 std::cout <<
"\nPress Enter to continue...";
48 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
60 std::cout <<
"--- Binary Search Tree Menu ---\n";
61 std::cout <<
"1. Insert a value\n";
62 std::cout <<
"2. Delete a value\n";
63 std::cout <<
"3. Search for a value\n";
64 std::cout <<
"4. Inorder traversal\n";
65 std::cout <<
"5. Level-order traversal\n";
66 std::cout <<
"6. Exit\n";
67 std::cout <<
"Enter your choice: ";
72 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
73 std::cout <<
"Invalid input.\n";
80 std::cout <<
"Exiting program...\n";
91 std::cout <<
"Enter value to insert: ";
94 std::cout <<
"Value inserted.\n";
98 std::cout <<
"Enter value to delete: ";
101 std::cout <<
"Value deleted.\n";
103 std::cout <<
"Value not found.\n";
107 std::cout <<
"Enter value to search for: ";
110 std::cout <<
"Value found in the tree.\n";
112 std::cout <<
"Value NOT found.\n";
116 std::cout <<
"Inorder traversal:\n";
121 std::cout <<
"Level-order traversal:\n";
126 std::cout <<
"Invalid choice.\n";
Declaration of the BST (Binary Search Tree) class.
Iterative binary search tree storing integer values.
void levelOrder() const
Performs a level-order (breadth-first) traversal of the tree.
void inorder() const
Performs an inorder traversal of the tree.
void insert(int value)
Inserts a value into the BST.
bool remove(int value)
Removes a value from the BST if it exists.
bool search(int value) const
Searches for a value in the BST.