forked from super30admin/PreCourse-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
52 lines (43 loc) · 1.44 KB
/
Main.java
File metadata and controls
52 lines (43 loc) · 1.44 KB
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
public class Main {
public static void main(String args[])
{
//Exercise 1
BinarySearch ob = new BinarySearch();
int arr[] = { 2, 3, 4, 10, 40 };
int n = arr.length;
int x = 10;
int result = ob.binarySearch(arr, 0, n - 1, x);
if (result == -1)
System.out.println("Element not present");
else
System.out.println("Element found at index " + result);
//Exercise 3
LinkedList llist = new LinkedList();
for (int i=15; i>0; --i)
{
llist.push(i);
llist.printList();
llist.printMiddle();
}
//Exercise 2
int arr2[] = {10, 7, 8, 9, 1, 5};
int ne = arr2.length;
QuickSort obj = new QuickSort();
obj.sort(arr2, 0, ne-1);
System.out.println("sorted array");
obj.printArray(arr2);
//Exercise 4
int arr4[] = {12, 11, 13, 5, 6, 7};
MergeSort msort = new MergeSort();
System.out.println("Exercise 4: Given Array");
msort.printArray(arr4);
msort.sort(arr4);
System.out.println("\nSorted array");
msort.printArray(arr4);
//Exercise 5
IterativeQuickSort IterativeQuickSort = new IterativeQuickSort();
int arr5[] = { 4, 3, 5, 2, 1, 3, 2, 3 };
IterativeQuickSort.QuickSort(arr5, 0, arr5.length - 1);
IterativeQuickSort.printArr(arr5, arr5.length);
}
}