Skip to content

Commit

Permalink
QuickSort.java Implemented QuickSort in java.
Browse files Browse the repository at this point in the history
This adds QuickSort Algorithm which return the concatenation of the
quicksorted list of elements that are less than or equal to the pivot, the
pivot, and the quicksorted list of elements that are greater than the pivot.

Closes #150
  • Loading branch information
udayvig committed Oct 2, 2018
1 parent 6a7e79e commit a02dd41
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions merge_sort/Java/QuickSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package lecture9;

public class QuickSort {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("Enter size: ");
int n = s.nextInt();
int[] arr = new int[n];
System.out.println("Enter elements: ");
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
quicksort(arr,0,arr.length-1);
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
}
public static void quicksort(int arr[],int low, int high){
if(low>=high){
return;
}
int left=low;
int right=high;
int mid=(low+high)/2;
int pivot=arr[mid];
while(left<=right){
while(arr[left]<pivot){
left++;
}
while(arr[right]>pivot){
right--;
}
if(left<=right){
int temp=arr[left];
arr[left]=arr[right];
arr[right]=temp;
left++;
right--;
}
}
quicksort(arr,low,right);
quicksort(arr,left,high);
}

}

1 comment on commit a02dd41

@sangamcse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on a02dd41.

There are 38 results for the section all.space_checks. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 5
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 6
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 7
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 8
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 9
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 10
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 11
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 12
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 13
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 14
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 17
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 19
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 20
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 21
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 22
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 23
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 24
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 25
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 26
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 27
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 28
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 29
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 30
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 31
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 32
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 33
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 34
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 35
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 36
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 37
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 38
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 39
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 40
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 41
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 42
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 43
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 44
Line contains following spacing inconsistencies: - Tabs used instead of spaces. merge_sort/Java/QuickSort.java 45

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

Please sign in to comment.