Import java.util.*;
Fast-ranked implementation public class quiksort{//(1) Recursive implementation fast sort public static void QuickSort (Int[]s,int l,int R) {if (l<r) {
int i=l;
int j=r; int pivot=s[l];
Take the first number of each child array as the base while (I<J) {while (I<j&&s[j]>pivot)/Right-to-left j--;
if (j>i) {s[i++]=s[j];
while (I<j&&s[i]<pivot)//From left to right i++;
if (i<j) {s[j--]=s[i];
}} S[i]=pivot;
QuickSort (s,l,i-1);
QuickSort (S,I+1,R); }///non-recursive fast sort public static void Nonrecquicksort (int[] a,int Start,int end) {linkedlist<integer> stack = new linkedlist<integer> ();
Using the stack to simulate if (start < end) {Stack.push (end);
Stack.push (start);
while (!stack.isempty ()) {int L = Stack.pop (); int r = Stack.pop ();
int index = partition (A, L, R);
if (L < index-1) {Stack.push (index-1);
Stack.push (l);
} if (r > Index + 1) {Stack.push (R);
Stack.push (index+1); }}} public static int partition (int[] A, int start, int end) {int pivot = A[st
Art];
while (Start < end) {while (Start < end && A[end] >= pivot) end--;
A[start] = A[end];
while (Start < end && A[start] <= pivot) start++;
A[end] = A[start];
} A[start] = pivot;
return start; }//print array value public static void PrintArray (Int[]arr) {for (int i=0;i<arr.length;i++) {Syste
M.out.print (arr[i]+ "");
} System.out.println (); public static void Main (string[)args) {int[]arr={3,6,5,2,5,4,3,8};
PrintArray (arr);
QuickSort (arr,0,arr.length-1);
Nonrecquicksort (arr,0,arr.length-1);
PrintArray (arr);
}
}
A sort of dance algorithm
Http://v.youku.com/v_show/id_XMzMyODk4NTQ4.html