Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .idea/dailycodebase.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions day35/Java/QuickSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @date 21/5/21
* @author shaybrow
*/

import java.util.*;
import static org.junit.Assert.*;
import org.junit.Test;

public class QuickSort {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<arr.length;i++){
System.out.println("Enter next int");
arr[i]=sc.nextInt();

}
quickSort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
public static void quickSort (int [] input){
int left = 0;
int right = input.length-1;
if (left < right){
int position =partition(input, left, right);

quickSort(input, left, position-1);
quickSort(input, position+1, right);

}

}
private static int partition(int[] input, int left, int right){

int pivot = input[right];
int low = left -1;
for (int i = left; i <right ; i++) {
if (input[i] <= pivot){
low ++;
swap(input, i, low);
}
}
swap(input, right, low+1);
return low + 1;
}
private static void swap (int [] input, int i, int low){
int temp = input[i];
input[i] = input[low];
input[low] = temp;
}
public void testQuickSort (){
int [] test = {8,4,23,42,16,15};
quickSort(test);
int [] expect = {4,8,15,16,23,16};
assertArrayEquals(expect, test);

int [] test2 = {100, 75, 50, 25, 0};
quickSort(test2);
int [] expect2 = {0,25,50,75,100};
assertArrayEquals(expect2, test2);
}

}
1 change: 1 addition & 0 deletions day35/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
```js
to be added
```
### [Java Implementation](./Java/QuickSort.java)

### [C++ Implementation](./C++/quickSort.cpp)

Expand Down