Profil de Fengthis.Pray();PhotosBlogListesPlus Outils Aide

Blog


30 mars

窗外的风景

Milky Way
Light Road
Pearls
Pearls
(Minolta X300, Fuji100)
26 mars

我眼中有Cheer, 她头上有光环

(看图不说话)
镜头中的Cheer
镜头中的Cheer
Sentimental Kills
她的头上有光环
(March 21, 2009, 上海大舞台. Nikon D40, Minolta X300+Fuji400)
17 mars

我还是一名IT人员啊

Code
 1     class QuickSorter
 2     {
 3         public void DoSort(List<int> list)
 4         {
 5             QSort(list, 0, list.Count - 1);
 6         }
 7 
 8         private void QSort(List<int> list, int l, int u)
 9         {
10             if (l >= u)
11             {
12                 //lower >= upper, return
13                 return;
14             }
15 
16             int m = l; //at first, set the middle at left 1st slot
17 
18             for (int i = l + 1; i <= u; i++//start from left 2nd slot
19             {
20                 if (list[i] < list[l]) //compare with pivotValue(left 1st item: list[l])
21                 {
22                     //if current list[i] < the left 1st item value
23                     //"push" the smaller item before middle index by 1) middle index ++, 2) swap the smaller number and middle index item
24                     m++;
25                     Swap(list, i, m);
26                 }
27             }
28 
29             //now "i" reaches upper, the final step is set pivotValue(list[l]) to its correct middle position
30             Swap(list, l, m);
31             //Okay, we have set the pivotValue(list[l]) at its correct middle position of list[u, l]
32             //list[l, m-1] <= list[m] <= list[m+1, u]
33 
34             QSort(list, l, m - 1);
35             QSort(list, m + 1, u);
36         }
37 
38         private void Swap(List<int> list, int x, int y)
39         {
40             int temp = list[x];
41             list[x] = list[y];
42             list[y] = temp;
43         }
44 }