Created
September 28, 2014 19:39
-
-
Save digvijaybhakuni/157c166aea68ba78dadb to your computer and use it in GitHub Desktop.
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 com.learn.dbhakuni.ds; | |
import java.util.Arrays; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: dbhakuni | |
* Date: 28/9/14 | |
* Time: 10:04 PM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class QuickSort { | |
private static int partationIt(int[] arr, int s, int e){ | |
int pivot = arr[e]; | |
int t = e; | |
int b = s-1; | |
boolean w = true; | |
while (w){ | |
while (w){ | |
b++; | |
if(t==b) { | |
w = false; | |
break; | |
} | |
if(arr[b] > pivot ){ | |
arr[t] = arr[b]; | |
break; | |
} | |
} | |
while (w){ | |
t--; | |
if(t==b) { | |
w = false; | |
break; | |
} | |
if(arr[t] < pivot ){ | |
arr[b] = arr[t]; | |
break; | |
} | |
} | |
arr[t] = pivot; | |
} | |
return t; | |
} | |
public static int[] quickSort(int[] arr, int s, int e){ | |
if(s < e){ | |
System.out.println("sort ... "); | |
int split = partationIt(arr,s,e); | |
quickSort(arr, s, split-1); | |
quickSort(arr, split+1, e); | |
} | |
return arr; | |
} | |
public static void main(String[] a){ | |
int[] arr = new int[]{25,56,14,96,1,66,36,74,12,10}; | |
quickSort(arr,0, arr.length-1); | |
for (int i : arr){ | |
System.out.print(i+" "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment