看到的一个十分有想法的排序算法(有缺陷但值得借鉴)

源码

public class ArraySort implements  Runnable{
    private String num;
    public  ArraySort(int num){
        this.num =num+"";
    }
    public static void main(String[] args){
        int [] nums ={11,3,14,14,1,17,19};
        for (int i=0;i<nums.length;i++){
            new Thread(new ArraySort(nums[i])).start();
        }
    }
 public void  run(){
  try{
         Thread.sleep(Integer.parseInt(num));
         System.out.println(num);
    }catch( Exception e){
      e.printStackTrace();
  }
 }

缺点

如果两个数相等,并且start时间相近,那么唤醒时间先后不确定,这是一个不稳定的排序,要是这个排序中有很多个数组,数组中有很多个数的话,那估计要排很久才能排完!

优点

算法不是基本排序算法(冒泡,二分排序)很有创新精神,可以说是该程序的最大亮点,有很大的优化空间。

猜你喜欢

转载自blog.csdn.net/u010740917/article/details/89396505