Skip to content

Commit 9ae4094

Browse files
Merge pull request #1 from Aishwary2004Gupta/Aishwary2004Gupta-patch-1
QuickSort.java
2 parents 9dde8a7 + 120434c commit 9ae4094

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

QuickSort.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
public class quickSort {
2+
public static void main(String[] args) {
3+
int[] arr = {5,6,4,2,6,1,0};
4+
sort(arr, 0, arr.length-1);
5+
System.out.println(Arrays.toString(arr));
6+
7+
}
8+
9+
10+
static void sort(int[] nums, int low, int high) {
11+
if (low >= high){
12+
return;
13+
}
14+
15+
int start = low;
16+
int end = high;
17+
int mid = start + (end - start)/2;
18+
int pivot = nums[mid]; //contains the value
19+
20+
while (start <= end){
21+
while (nums[start] < pivot){
22+
start++;
23+
}
24+
while (nums[end] >pivot){
25+
end--;
26+
}
27+
28+
if (start <= end){
29+
int temp = nums[start];
30+
nums[start] = nums[end];
31+
nums[end] = temp;
32+
start++;
33+
end--;
34+
}
35+
}
36+
sort(nums, low, end);
37+
sort(nums, start, high);
38+
}
39+
}

0 commit comments

Comments
 (0)