锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国内精品久久久久久久久,久久se精品一区二区影院,久久精品国产99久久久古代http://www.shnenglu.com/JonsenElizee/category/13504.htmlSoftware Developing Blog <BR> <BR> "An idea is fragile . It can be killed by a scornful smile or a yawn .It can be mound down by irony and scared to death by a cold look." <BR> "Most cultures throughout human history have not liked creative individuals .They ignore them or kill them.It is a very efficient way of stopping creativity." <BR> <BR> ------Advertising boss Charles Browe and Howard Gardner ,professor at Harvard zh-cnThu, 21 Oct 2010 17:13:14 GMTThu, 21 Oct 2010 17:13:14 GMT60Quicker Quick-Sort http://www.shnenglu.com/JonsenElizee/archive/2010/09/23/127418.htmlJonsenElizeeJonsenElizeeThu, 23 Sep 2010 07:24:00 GMThttp://www.shnenglu.com/JonsenElizee/archive/2010/09/23/127418.htmlhttp://www.shnenglu.com/JonsenElizee/comments/127418.htmlhttp://www.shnenglu.com/JonsenElizee/archive/2010/09/23/127418.html#Feedback0http://www.shnenglu.com/JonsenElizee/comments/commentRss/127418.htmlhttp://www.shnenglu.com/JonsenElizee/services/trackbacks/127418.html鍏充簬蹇熸帓搴?/strong>

鎴戜滑閮界煡閬撳揩閫熸帓搴忔湁寰堝ソ鐨?/font>O(nlogn)錛岄偅涔堟洿蹇殑蹇熸帓搴忓湪鍝噷鍛紵涓嬮潰鏄垜鐨勫涔犺褰曘?/font>

錛嶏紞By JonsenElizee 2010/09/23

甯歌鐨勫揩閫熸帓搴?/font>

瀛︿範蹇熸帓搴忥紝鏈璁╀漢鐔熸倝鐨勬槸涓や釜ptr宸﹀彸鏉ュ洖鎸囷紝涓嬈℃帓搴忓悗灝辨妸涓涓?/font>mid鍊兼斁鍦ㄤ簡鍚堥傜殑浣嶇疆涓娿傝繖鏄垜涓涓湅鍙嬬殑闈為掑綊鐨?/font>C錛嬶紜瀹炵幇銆傛垜鏀瑰啓涓鐐圭偣錛屽氨鏄姞浜?/font>C鐨?/font>rand()鏉ヨ緗暟緇勫鹼紝鐒跺悗緙栬瘧榪愯榪欎釜綆楁硶錛屼綘鍙兘榪樹笉鑳介殢闅忎究渚跨殑鍐欏嚭榪欎釜綆楁硶錛屼絾鏁堟灉鐪熺殑寰堜笉涔愯錛屼篃涓嶇煡閬撹榪愯澶氫箙鎵嶈兘鎺掑簭瀹?6*50鐨勫瓧絎︿覆銆傚悗闈㈡垜浠細鐪嬪埌涓涓緢綺炬倣鐨勭畻娉曘傘傘?/font>

 1 #include <stack>
 2 #include <vector>
 3 #include <iostream>
 4 #include <stdlib.h>
 5 #include <stdio.h>
 6 #include <time.h>
 7 
 8 using namespace std;
 9 
10 typedef struct _record
11 {
12     int begin;
13     int end;
14 }record;
15 
16 void quick_sort(int a[],int len)
17 {
18     vector<record> do_job;
19     record temp;
20     temp.begin = 0;
21     temp.end = len-1;
22     do_job.push_back(temp);
23 
24     while (do_job.size()  != 0) {
25         record temp = do_job.back();
26         do_job.pop_back();
27     
28         int low = temp.begin;
29         int high = temp.end;
30         int key = a[low];
31         while (low < high) {
32             while(low < high && a[high] >= key) high--;
33             a[low] = a[high];
34             while(low < high && a[low] <= key) low++;
35             a[high] = a[low];
36         }
37         a[low] = key;
38 
39         record temp1;
40         temp1.begin = temp.begin;
41         temp1.end = low-1;
42         if (temp1.begin < temp1.end) { do_job.push_back(temp1); }
43 
44         record temp2;
45         temp2.begin = low+1;
46         temp2.end = temp.end;
47         if (temp2.begin < temp2.end) { do_job.push_back(temp2); }
48     }
49 }
50 int main()
51 {
52     int a[26*50];
53     int i = 0;
54     while(i < 26*50) a[i] = rand() % 100;
55     int count =sizeof(a) / sizeof(int);
56     quick_sort(a,count);
57     for (int i = 0; i < count; i++) cout<<a[i]<<endl;
58     return 0;
59 }
60 


鏇寸畝鏇村揩蹇熸帓搴?/font>

榪欑蹇熸帓搴忎笉鏄渶蹇殑錛岀壒鍒槸鍩烘湰鏈夊簭鏃朵細閫鍖栧埌O(n^2)錛岀悊璁轟笂鍩轟簬姣旇緝鐨勬帓搴忎笉浼氬皬浜?/font>O(nlogn)錛屼絾榪樻槸鏈夊姞閫熺殑鍙兘銆備笅闈㈣繖涓槸銆?/font>Programming Pearls 2nd銆嬮噷闈㈢殑鏂規硶錛岃繖涓畻娉曠湡鐨勫緢綺炬倣錛岃繍琛屽畬26*50鐨勪竴涓帓搴忥紝鍙渶瑕?.09縐掞紝鎴戠殑瀹炵幇濡備笅銆?/font>


榪愯鏃舵槸緇欑殑涓涓暱搴︿負26*50鐨勪竴涓瓧絎︽暟緇勶紝瀵瑰畠榪涜鎺掑簭錛?/font>



鏇寸畝鏇村揩蹇熸帓搴忥紜錛?/font>

鐮旂┒涓婇潰綆楁硶鐨勬墽琛岃繃紼嬶紝閬靛驚澶у笀鐨勬濊礬錛屾垜鏀瑰啓浜嗙畻娉曪紝鍦ㄦ垜鐨?/font>X61錛?/font>Redhat EL5涓婅繍琛岄熷害姣斾笂闈㈢殑綆楁硶蹇簡8鍊嶏紝涔熷氨鏄繍琛屽畬26*50闀跨殑鎺掑簭錛屽彧闇瑕?.01縐掞紒鏈鍚庢垜鏄庣櫧涓涓亾鐞嗭紝瑕佹湁鎬濇兂錛岃鏈夋瘏鍔涳紝瑕佹湁瀹炶返銆傚畬紼挎椂錛屾垜鍙戠幇榪欎釜綆楁硶榪樻湁鏀硅繘鐨勪綑鍦般傜壒鍜屽ぇ瀹跺垎浜傚澶氭寚鐐廣?/font>

榪愯杈撳叆鍜?/font>quick.c涓殑涓鏍鳳細

榪愯緇撴灉瀵規瘮

甯歌鐨勯偅涓潪閫掑綊鐨勭畻娉曚粠鎴戝啓榪欎釜鏂囦歡鍒扮幇鍦紝瀹冭繕鍦ㄨ繍琛岀潃銆傘傘?/font>

絎簩涓拰絎笁涓椂闂村姣斿涓嬪浘錛?/font>

(鍔犱笉鍔犱紭鍖栵紞O3閮芥槸涓鏍風殑緇撴灉錛屽湪鎴戠殑X61涓婏紝gcc version 4.1.2 20080704 (Red Hat 4.1.2-48))


鏀硅繘鐨?/font>myquick.c鐨勮繍琛屾椂闂存槸quick.c鐨?/font>1/9銆?/font>

鏈鍚庯紝鎴戜笉寰椾笉鐢?/font>Ctrl錛?/font>C鎶婇偅涓父瑙勭殑緇?/font>KILL鎺夈?/font>

Real, User and Sys process time statistics

One of these things is not like the other. Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process.
    *Real is wall clock time - time from start to finish of the call. This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete).
    *User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.
    *Sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like 'user', this is only CPU time used by the process.
      User+Sys will tell you how much actual CPU time your process used.

 

婧愪唬鐮?/font>

鏍稿績綆楁硶瀵規瘮鍥?/font>



quick.c婧愪唬鐮?/font>

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <time.h>
 5 
 6 void quick(char* str, int low, int hig);
 7 void swap(char* a, char* b);
 8 
 9 int main()
10 {
11     char ary[] = 錛忥紡26錛?0闀跨殑瀛楃涓叉暟緇勶紝鍐呭鍙傝冧笂鍥俱?/span>
12     char* str = ary;
13     printf("calling quick");
14     quick(str, 0, strlen(str)-1);
15     return 0;
16 }
17 
18 void quick(char* str, int low, int hig) {
19     if(low >= hig) return;
20     srand(time(NULL));
21     // get a random key
22     //swap(str + low, str + low + (rand() % (hig - low + 1)));
23     int i = low, j = hig + 1, key = str[low];
24     while(1)
25     {
26         while(++<= hig && str[i] <= key);
27         while(-->= low && str[j] >  key);
28         if(i > j) break// no need to do swap
29         swap(str + i, str + j);
30     }
31     swap(str + low, str + i - 1); // swap key to i-1 position
32     quick(str, low, i - 2);
33     quick(str, i, hig);
34 }
35 
36 void swap(char* a, char* b) {
37     if(a == b) return;
38     *^= *b; *^= *a; *^= *b;
39 }
40 

 

 

myquick.c婧愪唬鐮?/font>

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <time.h>
 5 
 6 void myquick(char* str, int low, int hig);
 7 void swap(char* a, char* b);
 8 
 9 int main()
10 {
11     char ary[] = 錛忥紡26錛?0闀跨殑瀛楃涓詫紝鍚宷uick.c鐨勮緭鍏ャ?/span>
12     char* str = ary;
13     printf("calling myquick");
14     myquick(str, 0, strlen(str)-1);
15     return 0;
16 }
17 
18 void myquick(char* str, int low, int hig) {
19     if(low >= hig) return;// no need to sort elements
20     // elements in the right of [m] are not sorted
21     int m = low, i = low, j = hig, key = low;
22     // skip any elements that <= [key]
23     while(i <= hig && str[i] <= str[key]) {i++; m++;}
24     // skip elements > [key]
25     while(j >= low && str[j] > str[key]) j--;
26     // initially, i==j is impossible
27     while(i <= j) {
28         // swap small one to m-position
29         if(str[i] <= str[key]) { swap(str + m++, str + i); }
30         i++;
31     }
32     swap(str + low, str + m-1);
33     myquick(str, low, m - 2);
34     myquick(str, m, hig);
35     return;
36 }
37 
38 void swap(char* a, char* b) {
39     if(a == b) return;
40     *^= *b; *^= *a; *^= *b;
41 }
42 






]]>
久久婷婷五月综合97色| 精品久久久久久国产91| 2021最新久久久视精品爱| 久久亚洲AV成人无码软件| 精品国产青草久久久久福利| 97久久久精品综合88久久| 久久精品国产WWW456C0M| 色播久久人人爽人人爽人人片AV| 少妇精品久久久一区二区三区| 久久se精品一区二区| 无码人妻少妇久久中文字幕| 久久66热人妻偷产精品9| 欧美久久一级内射wwwwww.| 久久久久国产精品熟女影院| 久久99精品久久久久久齐齐| 亚洲AV无一区二区三区久久| 国产真实乱对白精彩久久| 久久综合香蕉国产蜜臀AV| 欧美日韩中文字幕久久久不卡 | 成人久久精品一区二区三区| 国产精品视频久久久| 久久天天日天天操综合伊人av| 精品久久8x国产免费观看| 精品国产日韩久久亚洲| 狠狠色综合久久久久尤物| 97久久久久人妻精品专区| 久久综合九色综合网站| 2021国产精品午夜久久 | 国产精品成人99久久久久 | 武侠古典久久婷婷狼人伊人| 久久福利青草精品资源站| 99久久无色码中文字幕人妻| 欧美激情精品久久久久久久九九九 | 国产999精品久久久久久| 99久久婷婷免费国产综合精品| 久久久久久久波多野结衣高潮 | 久久中文精品无码中文字幕| 精品久久久久中文字| segui久久国产精品| 精品无码久久久久久久久久| 国产精品内射久久久久欢欢|