Why don't you try to write one yourself? Do you know the algorithm?
[CODE=java] public class QuickSort {
int i; // Array index
int j; // Array index
/**
* @precondition Unsorted elements
* @postcondition Sorted elements
* @param qsArrays
* @param len
*/
public void setQuickSort(in t qsArrays[], int len) {
setQuicksort(qs Arrays, 0, len - 1);
}
private void setQuicksort(in t qsArrays[], int left, int right) {
int middle = left;
//block where array division starts
swap(qsArrays, left, (left + right) / 2);
for (int i = left + 1; i <= right; i++) {
if (qsArrays[i] <= qsArrays[left]) {
middle++;
//recursive function for swap
swap(qsArrays, i, middle);
}
}
//recursive method o divide array into its child
swap(qsArrays, left, middle);
// Blockfor soerting arrays after the list is divided into sub array
if (left + 1 < middle) {
setQuicksort(qs Arrays, left, middle - 1);
}
if (middle + 1 < right) {
setQuicksort(qs Arrays, middle + 1, right);
}
} // end setQuicksort
/**
* Swap numbers
*
* @param list
* @param a
* @param b
*/
private void swap(int list[], int a, int b) {
int temp = list[a]; //temp holds first number
list[a] = list[b]; //first index holds a value second index
list[b] = temp; // second index value holds a value of temp variable
}
/**
* The main method illustrates the use of a quick sort to sort a
* small array with 5 values
* @precondition: (None)
* @Postcondition: Sorted Array
*/
public static void main(String str[]) {
//array Initialization
int[] qsArrays = new int[5];
//insert elements into array
qsArrays[0] = 20;
qsArrays[1] = 10;
qsArrays[2] = 50;
qsArrays[3] = 100;
qsArrays[4] = 05;
// Print the array before sorting:
System.out.prin tln("Data before Soring ");
System.out.prin tln("********** ****** ");
//block to print unsorted elements
for (int val = 0; val < 5; val++) {
System.out.prin tln("Value at index" + val + " = " + qsArrays[val]);
}
//block to print sorted elements
for (int val = 0; val < 5; val++) {
System.out.prin tln("Value at index" + val + " = " + qsArrays[val]);
}
}
}
[/CODE]
this is complex... i need simple.....
Last edited by r035198x; May 22 '07, 06:04 PM.
Reason: added code tags
That quicksort implementation is as simple as they come. Don't just try to scrape
"TeH CoDeZ!!!11eleve n UGRENT" from the internet; think for yourself instead.
That quicksort implementation is as simple as they come. Don't just try to scrape
"TeH CoDeZ!!!11eleve n UGRENT" from the internet; think for yourself instead.
kind regards,
Jos
do not try to put down any one if u know the concept let me.. kno that program is designed by me.....
thank you
Comment