89 }
90 }
91 }
92
93 private static void Swap(ref int l, ref int r)
94 {
95 int s;
96 s = l;
97 l = r;
98 r = s;
99 }
100
101 /**//// <summary>
102 /// 快速排序法
103 /// </summary>
104 /// <param name="list"></param>
105 /// <param name="low"></param>
106 /// <param name="high"></param>
107 public static void Sort(int list, int low, int high)
108 {
109 int pivot;
110 int l, r;
111 int mid;
112 if (high <= low)
113 return;
114 else if (high == low + 1)
115 {
116 if (list[low] > list[high])
117 Swap(ref list[low], ref list[high]);
118 return;
119 }
120 mid = (low + high) >> 1;
121 pivot = list[mid];
122 Swap(ref list[low], ref list[mid]);
123 l = low + 1;
124 r = high;
125 do
126 {
127 while (l <= r && list[l] < pivot)
128 l++;
129 while (list[r] >= pivot)
130 r--;
131 if (l < r)
132 Swap(ref list[l], ref list[r]);
133 } while (l < r);
134 list[low] = list[r];
135 list[r] = pivot;
136 if (low + 1 < r)
137 Sort(list, low, r - 1);
138 if (r + 1 < high)
139 Sort(list, r + 1, high);
140 }
141 }
142}
143