Toi rapide java
import java.util.Arrays;
//so fun to run//try it (;
//Illustrate array in size of 100 Million Integers
//global arrays only!!
public class Quick {
static int[] arr = new int[10000000];
public static void main(String[] args) {//only use with global array!
for(int i=0; i<arr.length;i++){
arr[i]= (int)(Math.random()*1000);
}
quickSort(0, arr.length-1, arr[arr.length-1]);
//(send 0 to lowi,
//send the last index in the array to higi,
//send to pivot the last value in the array)
System.out.println(Arrays.toString(arr));
}
public static void quickSort(int lowi,int higi,int pivot){
if(higi<=lowi)
return;
if(higi - lowi <1)
return;
if(higi - lowi == 1){
if(arr[lowi]>arr[higi])
swap(lowi, higi);
return;
}
int temp, next = arr[lowi];
int higiS = higi, lowiS = lowi,pos = lowi;
while(higi-lowi >= 1){
if(next<pivot){
temp = arr[higi];
if(higi == higiS)
temp = arr[++pos];
else
temp = arr[higi];
arr[higi--] = next;
}
else{
if(lowi<=pos)
temp = arr[++pos];
else
temp = arr[lowi];
arr[lowi++] = next;
}
next = temp;
}
if(lowi<pos)
lowi = pos-1;
arr[lowi] = pivot;
quickSort(lowi+1, higiS, arr[higiS]);
if(lowi-1>=0)
quickSort(lowiS, lowi-1, arr[lowi-1]);
return;
}
public static void swap(int fI,int sI){
int temp = arr[fI];
arr[fI] = arr[sI];
arr[sI] = temp;
}
}
Elegant Elephant