标签:选择 tostring one index temp pre 冒泡 clone import
import java.util.Arrays;
public class MyTest {
public static void main(String[] args) throws CloneNotSupportedException {
int[] x={11,2,33,44,21,5,33,22,33,45,2,50};
/* //冒泡排序:
int[] x={11,2,33,44,21,5,33,22,33,45,2,50};
for (int i = 0; i < x.length-1; i++) {
for(int j=0;j<x.length-i-1;j++) {
if (x[j] > x[j + 1]) {
int s = x[j];
x[j] = x[j + 1];
x[j + 1] = s;
}
}
}
System.out.println("Arrays.toString(x) = " + Arrays.toString(x));*/
//选择排序
/* for (int i = 0; i < x.length-1; i++) {
int j;
int index=i;
for(j=i+1;j<x.length;j++){
if(x[index]>x[j]){
index=j;
}
}
int s=x[i];
x[i]=x[index];
x[index]=s;
}
System.out.println(Arrays.toString(x));*/
//快速排序
/* quickSort(x,0,x.length-1);
System.out.println("Arrays.toString(x) = " + Arrays.toString(x));
}
public static void quickSort(int[] x,int start,int last){
if (start<last){
int s=fastSout(x,start,last);
quickSort(x,start,s-1);
quickSort(x,s+1,last);
}
}
public static int fastSout(int[] x,int start,int lastright){
int left = start+1;
boolean tag = true;
while (tag){
while (left<=lastright&&x[left]<=x[start]){
left+=1;
}
while (left<=lastright&&x[lastright]>=x[start]){
lastright-=1;
}
if(left>lastright){
tag=false;
}else {
int temp=x[left];
x[left]=x[lastright];
x[lastright]=temp;
}
}
int t=x[start];
x[start]=x[lastright];
x[lastright]=t;
return lastright;*/
}
}
标签:选择 tostring one index temp pre 冒泡 clone import
原文地址:https://www.cnblogs.com/project-zqc/p/11707747.html