import java.util.Arrays;
public class ArrayDemo2_3 {
public static void main(String []args) {
//-----------------------冒泡排序
int[] num1 = new int[]{2,6,7,9,8,3,1,10};
for(int i= 0;i
for(int j = 0;j
if(num1[j]>num1[j+1]) {
int temp = num1[j+1];
num1[j+1] = num1[j];
num1[j]=temp;
}
}
}
for(int i = 0;i
System.out.print(num1[i]+" ");
}
//-----------------------选择排序
int[] num2 = new int[]{2,6,7,9,8,3,1,10};
for(int i = 0;i
for(int j = i+1;j
if(num2[i]>num2[j]) {
int temp = num2[j];
num2[j] = num2[i];
num2[i] = temp;
}
}
}
System.out.println();
for(int i = 0;i
System.out.print(num2[i]+" ");
}
//--------------------------插入排序
int[] num3 = new int[]{2,6,7,9,8,3,1,10};
int temp;
for(int i = 1;i
temp = num3[i];
int j = i;
while(j>0&&temp
num3[j] = num3[j-1];
j--;
}
num3[j] = temp;
}
System.out.println();
for(int i = 0;i
System.out.print(num3[i]+" ");
}
//----------------------------使用javaAPI中文文档直接调用类方法
int[] num4 = new int[]{2,6,7,9,8,3,1,10};
Arrays.sort(num4);//直接调用升序方法
System.out.println();
for(int i = 0;i
System.out.print(num4[i]+" ");
}
}
}