1.冒泡排序
private int[] deal(int[] list){
for(int i=0;i<list.length-1;i++){
for(int j=i+1;j<list.length;j++){
int temp;
if(list[i]>list[j]){
temp = list[i];
list[i]=list[j];
list[j]=temp;
}
}
}
return list;
}
2.鸡尾酒排序
public static int[] cocktailSort(int[] src)
{
//将最小值排到队尾
for(int i = 0 ; i < src.length/2 ; i++)
{
for(int j = i ; j < src.length-i-1 ; j++)
{
if(src[j] < src[j+1])
{
int temp = src[j];
src[j] = src[j+1];
src[j+1] = temp;
}
System.out.println("交换小"+Arrays.toString(src));
}
//将最大值排到队头
for(int j = src.length-1-(i+1); j > i ; j--)
{
if(src[j] > src[j-1])
{
int temp = src[j];
src[j] = src[j-1];
src[j-1] = temp;
}
System.out.println("交换大"+Arrays.toString(src));
}
System.out.println("第"+i+"次排序结果:"+Arrays.toString(src));
}
return src;
}
3.二叉树排序
4.合并排序
public static int[] mergeSort(int[] data1,int[] data2)
{
int[] temp=new int[data1.length+data2.length];
int i=0,j=0,iter=0;
for(;i<data1.length&&j<data2.length;) {
if(data1[i]<=data2[j]) {
temp[iter]=data1[i];
iter++;
i++;
} else {
temp[iter]=data2[j];
iter++;
j++;
}
}
for(;i<data1.length;i++,iter++)
temp[iter]=data1[i];
for(;j<data2.length;j++,iter++)
temp[iter]=data2[j];
return temp;
}