JAVA_三大排序_选择冒泡插入

//一、 插入 排序
package MyPackage;

import java.util.Arrays;

public class ArraySort{
public static void main(String[] args) {
int[] a = {8,3,7,2,1,9};
for(int t=1;t
int temp=a[t];
for(int i= t-1 ;i>=0;i--){
if(temp
a[i+1]=a[i];
a[i] = temp;
}
}
}
System.out.println(Arrays.toString(a));
}
}


//二、 选择 排序
public class TestClass {
public static void main(String[] args) {
int[] ary = new int[]{8,3,7,2,1,9};
for(int i=0;i
for(int j= i+1 ;j
if(ary[i]>ary[j]){
int temp =ary[i];
ary[i] = ary[j];
ary[j] = temp;
}
}
}
System.out.println(Arrays.toString(ary));
}
}

//三、 冒泡 排序(笔试常测项目)
int[] ary = new int[]{8,3,7,2,1,9};
for(int i=0;i
for(int j=0;j< ary.length-1-i ;j++){
if(ary[j+1]
int temp = ary[j];
ary[j] = ary[j+1];
ary[j+1] = temp;
}
}
}
System.out.println(Arrays.toString(ary));

你可能感兴趣的:(JAVA,基础知识,java)