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

     private static int sortUnit(int[] array, int low, int high)
            {
                int key = array[low];
                while (low < high)
                {
                    /*从后向前搜索比key小的值*/
                    while (array[high] >= key && high > low)
                        --high; 
                    /*比key小的放左边*/
                    array[low] = array[high];   
                    /*从前向后搜索比key大的值,比key大的放右边*/
                    while (array[low] <= key && high > low)
                        ++low; 
                    /*比key大的放右边*/
                    array[high] = array[low];
                }
                /*左边都比key小,右边都比key大。//将key放在游标当前位置。//此时low等于high */
                array[low] = key;
                foreach (int in array)
                {
                    Console.Write("{0} ", i);
                }
                Console.WriteLine();
                return high;
            }    
            /**快速排序 
    *@paramarry 
    *@return */
            public static void sort(int[] array, int low, int high)
            {
                if (low >= high)
                    return
                /*完成一次单元排序*/
                int index = sortUnit(array, low, high); 
                /*对左边单元进行排序*/
                sort(array, low, index - 1);
                /*对右边单元进行排序*/
                sort(array, index + 1, high);
            }

      

  • 相关阅读:
    计算机通信网
    程序员面试——数学和概率
    位移枚举
    OC中的宏定义
    配置Xcode的Device Orientation、AppIcon、LaunchImage
    Xcode中的Project和Target
    NSObject
    CG
    UICollectionViewLayout
    UICollectionView
  • 原文地址:https://www.cnblogs.com/wuhailong/p/4881431.html
Copyright © 2011-2022 走看看