j将测试进行到底~~

排序算法之三(选择排序)

上一篇 / 下一篇  2008-10-23 09:55:12 / 天气: 大风 / 心情: 平静 / 个人分类:数据结构算法


public class SelectSort {
    public void SelectSort(int[] array){
        for(int i = 0;i<array.length;i++){
            int temp = array[i];
            int min = i;
            for(int j=i;j<array.length;j++){
                if(array[min]>array[j]){
                    min = j;
                }
            }
            array[i] = array[min];
            array[min] = temp;
        }
    }
    
    public void print(int[] array){
        for(int i=0;i<array.length;i++){
            if(i<array.length-1){
            System.out.print(array[i]+",");
            }
            else
                System.out.print(array[i]);
        }
        System.out.println();
    }
   
    public static void main(String[] args){
        int[] array = {10,9,8,7,6,5,4,3,2,1};
        SelectSort seleSort = new SelectSort();
        seleSort.print(array);
        seleSort.SelectSort(array);
        seleSort.print(array);
    }
}
 

TAG: 数据结构算法

 

评分:0

我来说两句

日历

« 2024-05-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 7965
  • 日志数: 16
  • 建立时间: 2008-10-20
  • 更新时间: 2009-04-03

RSS订阅

Open Toolbar