- Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathExercise_5.java
More file actions
Latest commit
36 lines (32 loc) · 991 Bytes
/
Copy pathExercise_5.java
File metadata and controls
36 lines (32 loc) · 991 Bytes
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
classIterativeQuickSort {
voidswap(intarr[], inti, intj)
{
//Try swapping without extra variable
}
/* This function is same in both iterative and
recursive*/
intpartition(intarr[], intl, inth)
{
//Compare elements and swap.
}
// Sorts arr[l..h] using iterative QuickSort
voidQuickSort(intarr[], intl, inth)
{
//Try using Stack Data Structure to remove recursion.
}
// A utility function to print contents of arr
voidprintArr(intarr[], intn)
{
inti;
for (i = 0; i < n; ++i)
System.out.print(arr[i] + " ");
}
// Driver code to test above
publicstaticvoidmain(Stringargs[])
{
IterativeQuickSortob = newIterativeQuickSort();
intarr[] = { 4, 3, 5, 2, 1, 3, 2, 3 };
ob.QuickSort(arr, 0, arr.length - 1);
ob.printArr(arr, arr.length);
}
}