Helo there, I am having trouble identifying where I have gone wrong in the below code that I have written for BST (Binary Search Tree) java program: public static void main(String[] args) { Scanner scan = new Scanner(System.in); BST B1 = new BST(); int promt = 1; while (promt >= 1 && promt <= 8) { System.out.println("\nPlease select any of the following options\n"); System.out.println("1. Insert an element into the BST"); System.out.println("2. Search for an element in the BST"); System.out.println("3. Find the maximum element from the BST"); System.out.println("4. Find the minimum element from the BST"); System.out.println("5. Print elements in the BST in preorder"); System.out.println("6. Print elements in the BST in postorder"); System.out.println("7. Print elements in the BST in inorder"); System.out.println("8. Delete an element"); System.out.println("Anything else to exit the program"); promt = scan.nextInt(); switch(promt) { case 1 : System.out.println("Enter any value element to insert in BST"); B1.insert(scan.nextInt()); break; case 2: System.out.println("Enter any element to search in the BST"); B1.search(scan.nextInt()); break; case 3: System.out.println("Find Maximum"); B1.findMax(scan.nextInt()); break; case 4: System.out.println("Find Minimum"); B1.findMin(scan.nextInt()); break; case 5: System.out.println("\n Preorder: "); B1.preorder(); break; case 6: System.out.println("\n Postorder: "); B1.postorder(); break; case 7: System.out.println("\n Inorder: "); B1.inorder(); break; case 8: System.out.println("Delete element"); B1.delete(); case 9: break; } } Can someone please help me with this, please? Every time I run the program and enter a value (for example: to insert an element into BST) I keep on getting the same set of options over and over again. Can someone help, please? Thanks.
Helo there, I am having trouble identifying where I have gone wrong in the below code that I have written for BST (Binary Search Tree) java
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
BST B1 = new BST();
int promt = 1;
while (promt >= 1 && promt <= 8)
{
System.out.println("\nPlease select any of the following options\n");
System.out.println("1. Insert an element into the BST");
System.out.println("2. Search for an element in the BST");
System.out.println("3. Find the maximum element from the BST");
System.out.println("4. Find the minimum element from the BST");
System.out.println("5. Print elements in the BST in preorder");
System.out.println("6. Print elements in the BST in postorder");
System.out.println("7. Print elements in the BST in inorder");
System.out.println("8. Delete an element");
System.out.println("Anything else to exit the program");
promt = scan.nextInt();
switch(promt)
{
case 1 :
System.out.println("Enter any value element to insert in BST");
B1.insert(scan.nextInt());
break;
case 2:
System.out.println("Enter any element to search in the BST");
B1.search(scan.nextInt());
break;
case 3:
System.out.println("Find Maximum");
B1.findMax(scan.nextInt());
break;
case 4:
System.out.println("Find Minimum");
B1.findMin(scan.nextInt());
break;
case 5:
System.out.println("\n Preorder: ");
B1.preorder();
break;
case 6:
System.out.println("\n Postorder: ");
B1.postorder();
break;
case 7:
System.out.println("\n Inorder: ");
B1.inorder();
break;
case 8:
System.out.println("Delete element");
B1.delete();
case 9:
break;
}
}
Can someone please help me with this, please? Every time I run the program and enter a value (for example: to insert an element into BST) I keep on getting the same set of options over and over again.
Can someone help, please?
Thanks.
Step by step
Solved in 2 steps