zoukankan      html  css  js  c++  java
  • 快速排序法

    package src;
     
    public class QSort
    {
     
        /**
         * @param args
         */
        public static void main(String[] args)
        {
            // TODO 自动生成方法存根
            quicksort qs = new quicksort();
            int data[] = {44,22,2,32,54,22,88,77,99,11};
            qs.data = data;
            qs.sort(0, qs.data.length-1);
            qs.display();
        }
     
    }
     
     
    class quicksort
    {
        public int data[];
         
        private int partition(int sortArray[],int low,int hight)
        {
            int key = sortArray[low];
             
            while(low<hight)
            {
                while(low<hight && sortArray[hight]>=key)
                    hight--;
                sortArray[low] = sortArray[hight];
                 
                while(low<hight && sortArray[low]<=key)
                    low++;
                sortArray[hight] = sortArray[low];
            }
            sortArray[low] = key;
            return low;
        }
         
        public void sort(int low,int hight)
        {
            if(low<hight)
            {
                int result = partition(data,low,hight);
                sort(low,result-1);
                sort(result+1,hight);
            }
             
        }
         
        public void display()
        {
            for(int i=0;i<data.length;i++)
            {
                System.out.print(data[i]);
                System.out.print(" ");
            }
        }
    }
  • 相关阅读:
    Java 字符串,byte[],16进制的字符串互转
    Java中char的字节数
    有向图 获取回路转
    java字符串分割处理split及特殊符号 转
    java如何直接跳出外层循环 标签
    求有向图中两点间所有路径
    五周突破N1 第五周第三单元
    5周突破N1 惯用句 1
    5周N1 300P
    5周突破N
  • 原文地址:https://www.cnblogs.com/fqwsndc1314-5207788/p/6702248.html
Copyright © 2011-2022 走看看