zoukankan      html  css  js  c++  java
  • C# 内部的快速排序实现

     1 private void QuickSort(int[] map, int left, int right)
     2 {
     3     do
     4     {
     5         int index = left;
     6         int num2 = right;
     7         int num3 = map[index + ((num2 - index) >> 1)];
     8         do
     9         {
    10             while ((index < map.Length) && (this.CompareKeys(num3, map[index]) > 0))
    11             {
    12                 index++;
    13             }
    14             while ((num2 >= 0) && (this.CompareKeys(num3, map[num2]) < 0))
    15             {
    16                 num2--;
    17             }
    18             if (index > num2)
    19             {
    20                 break;
    21             }
    22             if (index < num2)
    23             {
    24                 int num4 = map[index];
    25                 map[index] = map[num2];
    26                 map[num2] = num4;
    27             }
    28             index++;
    29             num2--;
    30         }
    31         while (index <= num2);
    32         if ((num2 - left) <= (right - index))
    33         {
    34             if (left < num2)
    35             {
    36                 this.QuickSort(map, left, num2);
    37             }
    38             left = index;
    39         }
    40         else
    41         {
    42             if (index < right)
    43             {
    44                 this.QuickSort(map, index, right);
    45             }
    46             right = num2;
    47         }
    48     }
    49     while (left < right);
    50 }

    其中CompareKeys需要自己实现,也叫比较器,C#内部很多地方都要用到

  • 相关阅读:
    工科物理实验()中国大学MOOC答案(已更新)
    类似jar文件使用java无法打开问题
    python9、10章
    nmap的理解与利用(初级)
    常见端口
    配置优化
    删除表操作
    万能的map
    测试
    Mapper.xml
  • 原文地址:https://www.cnblogs.com/yayaxxww/p/3745867.html
Copyright © 2011-2022 走看看