/**
* <p>Title: main
* <p>Description: 选择排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 9, 8, 7, 2, 4 };
for (int i = 0; i < arry.length - 1; i++){
int min = i;
for (int j = i+1; j < arry.length; j++){
if (arry[min] > arry[j]){
min = j;
}
}
if (min != i){
int temp = arry[i];
arry[i] = arry[min];
arry[min] = temp;
}
}
List<Integer> list = new ArrayList<Integer>();
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
/**
* <p>Title: main
* <p>Description: 冒泡排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 8, 7, 2, 4 };
for (int i = 0; i < arry.length - 1; i++){
for(int j = i + 1; j < arry.length; j++){
//两组数据进行对比,然后排位
if (arry[i] > arry[j]){
int temp = arry[i];
arry[i] = arry[j];
arry[j] = temp;
}
}
}
List<Integer> list = new ArrayList<Integer>();
//循环打印出结果
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
/**
* <p>Title: main
* <p>Description: array快速排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 9, 8, 7, 2, 4 };
Arrays.sort(arry);
List<Integer> list = new ArrayList<Integer>();
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
/**
* <p>Title: main
* <p>Description: 插入排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 9, 8, 7, 2, 4 };
for (int i = 0; i < arry.length; i++){
for (int j = i; j > 0; j--){
if (arry[j] < arry[j-1]){
int temp = arry[j -1];
arry[j -1] = arry[j];
arry[j] = temp;
}else {
break;
}
}
}
List<Integer> list = new ArrayList<Integer>();
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
* <p>Title: main
* <p>Description: 选择排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 9, 8, 7, 2, 4 };
for (int i = 0; i < arry.length - 1; i++){
int min = i;
for (int j = i+1; j < arry.length; j++){
if (arry[min] > arry[j]){
min = j;
}
}
if (min != i){
int temp = arry[i];
arry[i] = arry[min];
arry[min] = temp;
}
}
List<Integer> list = new ArrayList<Integer>();
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
/**
* <p>Title: main
* <p>Description: 冒泡排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 8, 7, 2, 4 };
for (int i = 0; i < arry.length - 1; i++){
for(int j = i + 1; j < arry.length; j++){
//两组数据进行对比,然后排位
if (arry[i] > arry[j]){
int temp = arry[i];
arry[i] = arry[j];
arry[j] = temp;
}
}
}
List<Integer> list = new ArrayList<Integer>();
//循环打印出结果
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
/**
* <p>Title: main
* <p>Description: array快速排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 9, 8, 7, 2, 4 };
Arrays.sort(arry);
List<Integer> list = new ArrayList<Integer>();
for (int m : arry){
list.add(m);
}
System.out.println(list);
}
/**
* <p>Title: main
* <p>Description: 插入排序
* @param args
*/
public static void main(String[] args) {
int[] arry = { 6, 5, 3, 1, 9, 8, 7, 2, 4 };
for (int i = 0; i < arry.length; i++){
for (int j = i; j > 0; j--){
if (arry[j] < arry[j-1]){
int temp = arry[j -1];
arry[j -1] = arry[j];
arry[j] = temp;
}else {
break;
}
}
}
List<Integer> list = new ArrayList<Integer>();
for (int m : arry){
list.add(m);
}
System.out.println(list);
}