- public class SortTest {
-
- void selectSort(int[] sortIn){
- int i,j,temp,min=0;
- for(i=0;i<sortIn.length;i++){
- min=i;
- for(j=i;j<sortIn.length;j++){
- if(sortIn[j]<sortIn[min]) min=j;
- }
-
- swap(sortIn,i,min);
- }
- }
-
-
- void bubbleSort(int[] sortIn){
- for(int i=0;i<sortIn.length;i++){
- for(int j=sortIn.length-1;j>i;j--){
- if(sortIn[j]<sortIn[j-1])
- swap(sortIn,j-1,j);
- }
- }
- }
-
-
- void insertSort(int[] sortIn){
- for(int i=1;i<sortIn.length;i++){
- int temp=sortIn[i];
- int j=i-1;
- while(j>=0&&temp<sortIn[j]){
- sortIn[j+1]=sortIn[j];
- j--;
- }
- sortIn[j+1]=temp;
- }
- }
-
-
- void sheelSort(int[] sortIn){
- int d=sortIn.length;
- while(d>1){
- d=(d+1)/2;
- for(int i=0;i<sortIn.length-d;i++){
- if(sortIn[i+d]<sortIn[i]){
- swap(sortIn,i+d,i);
- }
- }
- }
- }
-
- void quickSort(int[] sortIn,int low,int high){
- int pivotpos;
- if(low<high){
- pivotpos=partition(sortIn,low,high);
- quickSort(sortIn,low,pivotpos-1);
- quickSort(sortIn,pivotpos+1,high);
- }
- }
-
- private int partition(int[] sortIn,int i,int j){
- int pivot=sortIn[i];
- while(i<j){
-
- while(i<j&&sortIn[j]>=pivot) j--;
- if(i<j){
- swap(sortIn,i,j);
- i++;
- }
-
-
- while(i<j&&sortIn[i]<=pivot) i++;
- if(i<j){
- swap(sortIn,i,j);
- j--;
- }
- }
- sortIn[i]=pivot;
- return i;
- }
-
-
- private void swap(int a[],int i,int j){
- int temp=a[i];
- a[i]=a[j];
- a[j]=temp;
- }
-
- public static void main(String[] args){
- int[] sortIn={49,38,56,97,76,13,27,99,55,3};
- SortTest ss=new SortTest();
-
-
-
-
-
- ss.quickSort(sortIn,0,sortIn.length-1);
- for(int num:sortIn){
- System.out.print(" "+num);
- }
- }
- }