首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

取舍排序法

2012-10-25 
选择排序法//选择排序法public class XuanZe {??public void xz(int[] in){?for(int i0iin.length-1i+

选择排序法

//选择排序法
public class XuanZe {
?
?public void xz(int[] in){
?for(int i=0;i<in.length-1;i++){
??for(int j=1+i;j<in.length;j++){
???if(in[i]>in[j]){
????int temp=in[i];
???????????????? in[i]=in[j];
???????????????? in[j]=temp;
??? }
??? }
??? }
?}
?
?public void display(int[] in){
??for(int i=0;i<in.length;i++){
???System.out.print(in[i]+" ");
??}
?}
?
?public static void main(String[] args){
??XuanZe xuanze=new XuanZe();
??int[] in=new int[]{5,2,41,4,3,8};
????? long star=System.nanoTime();
????? xuanze.xz(in);
????? long end=System.nanoTime();
????? System.out.println("选择时间用时:"+(end-star));
????? xuanze.display(in);
?}
}

热点排行