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

    http://www.oschina.net/code/snippet_120166_6102

    public class Quick
    {
        public static void main(String []args)
        {
            int arr[]={8,2,3,4,5,9};
            Quick q=new Quick();
            q.quickly(arr,0,arr.length-1);
            for (int i=0;i<arr.length;i++)
            {
                System.out.println("第"+i+"个数是: "+arr[i]);
            }
        }
        public int quick(int a[],int i,int j)
        {
            int r=i;
            int w=j;
            int x=a[i];
            while (i<j)
            {
                while (i<j & x<=a[j])
                {
                    j--;
                }
                if (i<j)
                {
                    a[i++]=a[j];
                }
                while (i<j & x>a[i])
                {
                    i++;
                }
                if (i<j)
                {
                    a[j--]=a[i];
                }
            }
            a[i]=x;
            System.out.println("下标为:"+i);
            return i;
        }
        public void quickly(int a[],int low,int hight)
        {
            if(low<hight)
            {
                int result=quick(a,low,hight);
                quickly(a,low,result-1);
                quickly(a,result+1,hight);
            }
        }

    }

  • 相关阅读:
    理解-NumPy
    python % format
    计算机三级网络技术考过指南
    jquery 增加与删除数组元素
    jquery 改变标签可见状态的几种方式
    pL/SQL 创建DBLIKN
    Oracle 数据类型详解
    状态模式例子---流程控制
    jqGrid 将行的字变成超连接
    表单提交详细介绍
  • 原文地址:https://www.cnblogs.com/MR-Guo/p/3337715.html
Copyright © 2011-2022 走看看