-
Notifications
You must be signed in to change notification settings - Fork 7
/
DriverBST.java
58 lines (50 loc) · 1.2 KB
/
DriverBST.java
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
import java.util.Scanner;
import tree.*;
public class DriverBST
{
public static void main(String args[])
{
BST bst=new BST();
Scanner sc=new Scanner(System.in);
boolean t=true;
Integer x,y;
while(t==true)
{
System.out.println("\n\nEnter 0 to break loop\nEnter 1 for insert function\nEnter 2 for search function\nEnter 3 for delete function\nEnter 4 for In-order traversal\nEnter 5 for Pre-order traversal\nEnter 6 for post-order traversal");
x=sc.nextInt();
switch(x)
{
case 0:
t=false;
break;
case 1:
System.out.println("Enter element to be added");
y=sc.nextInt();
bst.insert(y);
break;
case 2:
System.out.println("Enter element to be searched");
y=sc.nextInt();
System.out.println("Element found at "+bst.search(bst.getRoot(), y));
break;
case 3:
System.out.println("Enter element to be deleted");
y=sc.nextInt();
bst.delete(y);
break;
case 4:
bst.IOT(bst.getRoot());
System.out.println();
break;
case 5:
bst.preOT(bst.getRoot());
System.out.println();
break;
case 6:
bst.postOT(bst.getRoot());
System.out.println();
break;
}
}
}
}