-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.java
76 lines (71 loc) · 1.99 KB
/
Test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.binary.tree;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
BinaryTreeFunctions bin = new BinaryTreeFunctions();
Node root = null, end = null;
int ch = 0, num = 0;
Scanner s = new Scanner(System.in);
do {
System.out.printf(
"\nOPTIONS\n1.Insert\n2.Delete\n3.Search\n4.Level Order Display\n5.Inorder Display\n6.Exit\nChoice:");
ch = s.nextInt();
try {
switch (ch) {
case 1:
System.out.println("Enter the number to be inserted:");
num = s.nextInt();
root = bin.ins(root, num);
break;
case 2:
if (root != null) {
System.out.println("Enter the number to be deleted:");
num = s.nextInt();
root = bin.del(root, num, true);
} else {
System.out.println("!!!!!Tree is empty!!!!!");
}
break;
case 3:
if (root != null) {
System.out.println("Enter the number to be searched:");
num = s.nextInt();
end = bin.search(root, num);
if (end != null) {
System.out.println("*****Element found*****");
} else {
System.out.println("!!!!!Element not in tree!!!!!");
}
} else {
System.out.println("!!!!!Tree is empty!!!!!");
}
break;
case 4:
if (root != null) {
System.out.println("*****Level order traversal*****");
bin.Level(root);
} else {
System.out.println("!!!!!Tree is empty!!!!!");
}
break;
case 5:
if (root != null) {
System.out.println("*****Inorder traversal*****");
bin.inorder(root);
} else {
System.out.println("!!!!!Tree is empty!!!!!");
}
break;
case 6:
break;
default:
System.out.println("!!!!!Invalid option entered!!!!!");
}
} catch (Exception e) {
System.out.println("!!!!!Oops something went wrong.Please enter valid input!!!!!!");
s.nextLine();
}
} while (ch != 6);
System.out.println("THANK YOU!!!");
}
}