java插入排序算法2

来源:互联网 发布:mac 安全模式 编辑:程序博客网 时间:2024/06/11 14:21

插入排序1.2

具体思路:

代码实现:

public class ChoseSort {

public  ChoseSort(int a [] ) {

int tmp=0;

for(int i=1;i<a.length;i++) {

for(int j=i-1;j>=0;j--) {

if(a[j]>a[j+1]) {

    tmp=a[j];   

a[j]=a[j+1];

a[j+1]=tmp;

        }

      }

     }

    }

public static void main(String[]args) {

int arr[]= {10,2,5,9};

ChoseSortsort1=new ChoseSort(arr);

for(int a:arr) {

System.out.print(a+"  ");

    }

  }

 }


原创粉丝点击