Created
August 20, 2018 09:08
-
-
Save kimmking/517d93db764c86a1db0ffde3280e6f8d to your computer and use it in GitHub Desktop.
interview_quicksort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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