1.冒泡排序:
public void maoPaoSort(){
Integer[] in = new Integer[]{3,18,38,16,2,5,9,42,1,19,60};
int temp;
for(int i =0; i < in.length;i++){
for(int j = 0;j <= in.length-1;j++){
if(in[i] < in[j]){
temp=in[j];
in[j]=in[i];
in[i]=temp;
}
}
}
for(int k = 0;k< in.length; k++){
System.out.print(in[k]+" ");
}
}
2.快速排序
class SortNumber{
//快速排序
public int quickSort(int[] sortArray,int low,int hight){
int key = sortArray[low];
while(low < hight){
while(low < hight && sortArray[hight] >= key){
hight--;
}
sortArray[low] = sortArray[hight];
while(low < hight && sortArray[low] <= key){
low++;
}
sortArray[hight] = sortArray[low];
}
sortArray[low] = key;
return low;
}
public void sort(int low,int hight){
if(low < hight){
int result = quickSort(data,low,hight);
sort(low,result-1);
sort(result+1,hight);
}
}
}