Skip to content

Instantly share code, notes, and snippets.

@kimmking
Created August 20, 2018 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimmking/517d93db764c86a1db0ffde3280e6f8d to your computer and use it in GitHub Desktop.
Save kimmking/517d93db764c86a1db0ffde3280e6f8d to your computer and use it in GitHub Desktop.
interview_quicksort
package io.github.kimmking;
import java.lang.*;
class QuickSort
{
public static void main (String[] args) throws java.lang.Exception
{
int[] array = new int[]{5,1,6,2,4,3,8,9,0,10};
quickSort(array,0, array.length-1);
for (int i : array) {
System.out.print(i + ",");
}
System.out.println();
}
private static void quickSort(int[] arr,int start,int end){
if(start >= end ) return;
int c = start;
int current = arr[c];
for (int i = start+1;i<=end;i++){
if(arr[i]<current){
arr[c] = arr[i];
arr[i] = arr[c+1];
arr[c+1] = current;
c++;
}
}
quickSort(arr,start,c-1);
quickSort(arr,c+1,end);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment