About this application:
This application implements Quick Sort algorithm
Using the Divide
Come to one specific sort
In order to improve the algorithm
Source Code:
package quick
import java
import java
/**
* Sort the numbers using quick sort algorithm If there is any suggestion about
* this program
* Date:
*/
public class QuickSort {
public ArrayList<Double> storeNumbers;
public static QuickSort quickSort;
public boolean outputEnable;
public static void main(String args[]) {
System
quickSort = new QuickSort();
quickSort
quickSort
}
/**
* Input the numbers you want to sort
*/
public void inputNumbers() {
Scanner in = new Scanner(System
String s;
storeNumbers = new ArrayList<Double>();
while (true) {
System
s = in
// If the input is empty
if (s
System
outputEnable = false;
continue;
} else {
String[] a = s
// If the length is
if (a
System
outputEnable = false;
continue;
}
for (int i =
try {
storeNumbers
outputEnable = true;
} catch (NumberFormatException e) {
System
outputEnable = false;
storeNumbers
break;
}
}
}
// Sort the numbers
sort(
// Output the results
output();
storeNumbers
}
}
/**
* Get the pivot of the numbers
*
* @param start
* The start position of the numbers waiting for sort
* @param end
* The end position of the numbers waiting for sort
* @return the pivot of the numbers
*/
public int getPartitionPoint(int start
return (start + end) >>
}
/**
* Partition the numbers waiting for sort
* than the pivot
*
* @param before
* The start position of the numbers waiting for sort
* @param after
* The end position of the numbers waiting for sort
* @return the position of the pivot
*/
public int partition(int before
double temp;
int PartitionPoint = getPartitionPoint(before
temp = storeNumbers
// Put the first number in the position of pivot
storeNumbers
// Compare and exchange until before and after are equal
while (before != after) {
while ((before != after) && (storeNumbers
after
}
if (before < after) {
storeNumbers
before++;
}
while ((before != after) && (storeNumbers
before++;
}
if (before < after) {
storeNumbers
after
}
}
storeNumbers
return before;
}
/**
* Sort the numbers using iteration
*
* @param start
* The start position of the numbers waiting for sort
* @param end
* The end position of the numbers waiting for sort
*/
public void sort(int start
if (end
return;
int positionPoint = partition(start
sort(start
sort(positionPoint +
}
/**
* Output the results
*/
public void output() {
if (outputEnable == true) {
System
for (int i =
System
}
System
} else
return;
}
}
Black
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers after sort are:
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers after sort are:
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers after sort are:
Please input the numbers you need to sort(Note: seperate the numbers using comma
we
The numbers you input are not correct
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers you input are not correct
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers you input are not correct
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers you input are not correct
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers you input are not correct
Please input the numbers you need to sort(Note: seperate the numbers using comma
The numbers you input are not correct
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26043.html