锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国内精品久久久久影院日本 ,亚洲国产香蕉人人爽成AV片久久,久久综合伊人77777http://www.shnenglu.com/bon/zh-cnSun, 11 May 2025 00:12:32 GMTSun, 11 May 2025 00:12:32 GMT60merge sort pitfallshttp://www.shnenglu.com/bon/archive/2009/04/30/81561.htmlbonbonThu, 30 Apr 2009 05:57:00 GMThttp://www.shnenglu.com/bon/archive/2009/04/30/81561.htmlhttp://www.shnenglu.com/bon/comments/81561.htmlhttp://www.shnenglu.com/bon/archive/2009/04/30/81561.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/81561.htmlhttp://www.shnenglu.com/bon/services/trackbacks/81561.html
Now I would like to scan all basic algorithms, especially sorting and searching.

Let me first present a classic sorting algorithm - merge sort. Here is my code. Before I reach here, some mistakes are made, thus I note these "pitfalls" in the code

#include <stdlib.h>
#include <stdio.h>
#define MAX 1e9    // the biggest possible value of a int number is 2^31 - 1 which is approximately 10^9
#define SIZE 10

int *a;
int *b;
int *c;

// merge [p, q] and [q+1, r], where within each range number are sorted
void merge(int p, int q, int r)
{
    int k;
    int length = r - p +1;            // the length the range to be merge
    for (k = 0; k < q - p + 1; k++) {
        b[k] = a[p + k];             // copy number in a[p, q] to b
    }
    b[k] = MAX;             // b[k] = MAX, not b[k+1]=MAX
    for (k = 0; k < r - q; k++) {
        c[k] = a[q + 1 + k];             // copy number in a[q+1, r] to c
    }
    c[k] = MAX;             // c[k] = MAX, not c[k+1]=MAX

    /* BEGIN merging */
    int i = 0;
    int j = 0;
    for (k=0;k<length;k++) {             // do exactly length times of copy
        if (b[i] < c[j]) {
            a[p + k] = b[i++];          // be careful! a[p, r] is a whole range now, and watch out the base "p"
        } else {
            a[p + k] = c[j++];
        }
    }
}

void merge_sort(int l, int u)
{
    if (l == u) return;             // when to stop recursion? only one number needs no sorting
    int m = (l + u)/2;
    merge_sort(l, m);
    merge_sort(m + 1, u);
    merge(l, m, u);
}

int main()
{
    a = (int*)malloc(SIZE * sizeof(int));
    b = (int*)malloc(SIZE * sizeof(int));          // cache, avoid many "malloc" in the merge function
    c = (int*)malloc(SIZE * sizeof(int));          // this trick is from "Programming Pearls"
    int i;
    for (i = 0; i < SIZE; i++) {
        a[i] = SIZE - i;
    }
    merge_sort(0, SIZE - 1);                    // watch out the range
    for (i = 0; i < SIZE; i++) {
        printf("%d\n", a[i]);
    }
    return 1;
}



bon 2009-04-30 13:57 鍙戣〃璇勮
]]>
KMP (2)http://www.shnenglu.com/bon/archive/2008/07/31/57589.htmlbonbonThu, 31 Jul 2008 02:51:00 GMThttp://www.shnenglu.com/bon/archive/2008/07/31/57589.htmlhttp://www.shnenglu.com/bon/comments/57589.htmlhttp://www.shnenglu.com/bon/archive/2008/07/31/57589.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/57589.htmlhttp://www.shnenglu.com/bon/services/trackbacks/57589.html闃呰鍏ㄦ枃

bon 2008-07-31 10:51 鍙戣〃璇勮
]]>
POJ 2406http://www.shnenglu.com/bon/archive/2008/07/28/57360.htmlbonbonMon, 28 Jul 2008 08:48:00 GMThttp://www.shnenglu.com/bon/archive/2008/07/28/57360.htmlhttp://www.shnenglu.com/bon/comments/57360.htmlhttp://www.shnenglu.com/bon/archive/2008/07/28/57360.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/57360.htmlhttp://www.shnenglu.com/bon/services/trackbacks/57360.html闃呰鍏ㄦ枃

bon 2008-07-28 16:48 鍙戣〃璇勮
]]>
KMP綆楁硶http://www.shnenglu.com/bon/archive/2008/07/25/57124.htmlbonbonFri, 25 Jul 2008 03:45:00 GMThttp://www.shnenglu.com/bon/archive/2008/07/25/57124.htmlhttp://www.shnenglu.com/bon/comments/57124.htmlhttp://www.shnenglu.com/bon/archive/2008/07/25/57124.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/57124.htmlhttp://www.shnenglu.com/bon/services/trackbacks/57124.html闃呰鍏ㄦ枃

bon 2008-07-25 11:45 鍙戣〃璇勮
]]>
KDDcup(1) 闈炲畬鏁寸増http://www.shnenglu.com/bon/archive/2008/07/09/55688.htmlbonbonWed, 09 Jul 2008 01:55:00 GMThttp://www.shnenglu.com/bon/archive/2008/07/09/55688.htmlhttp://www.shnenglu.com/bon/comments/55688.htmlhttp://www.shnenglu.com/bon/archive/2008/07/09/55688.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/55688.htmlhttp://www.shnenglu.com/bon/services/trackbacks/55688.html闃呰鍏ㄦ枃

bon 2008-07-09 09:55 鍙戣〃璇勮
]]>
KDDCUP08http://www.shnenglu.com/bon/archive/2008/06/29/54898.htmlbonbonSun, 29 Jun 2008 02:52:00 GMThttp://www.shnenglu.com/bon/archive/2008/06/29/54898.htmlhttp://www.shnenglu.com/bon/comments/54898.htmlhttp://www.shnenglu.com/bon/archive/2008/06/29/54898.html#Feedback1http://www.shnenglu.com/bon/comments/commentRss/54898.htmlhttp://www.shnenglu.com/bon/services/trackbacks/54898.htmlWei鐨勬寚瀵間笅錛岃窡鏄鵑湶鍙傚姞浜?a >KDDCUP08鐨勬暟鎹寲鎺樻瘮璧涖傚湪榪欐姣旇禌涓殑鏁版嵁澶勭悊銆佺畻娉曚互鍙婂叾瀹冪殑鏀惰幏錛屼細浠ヨ繛杞界殑鏂瑰紡鍙戝嚭鏉ワ紝鏁鍚勪綅鍏蟲敞銆?

bon 2008-06-29 10:52 鍙戣〃璇勮
]]>
poj 2748http://www.shnenglu.com/bon/archive/2008/06/09/52663.htmlbonbonMon, 09 Jun 2008 07:29:00 GMThttp://www.shnenglu.com/bon/archive/2008/06/09/52663.htmlhttp://www.shnenglu.com/bon/comments/52663.htmlhttp://www.shnenglu.com/bon/archive/2008/06/09/52663.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/52663.htmlhttp://www.shnenglu.com/bon/services/trackbacks/52663.html闃呰鍏ㄦ枃

bon 2008-06-09 15:29 鍙戣〃璇勮
]]>
鏈闀垮叕鍏卞瓙搴忓垪錛坧ku 1936錛?/title><link>http://www.shnenglu.com/bon/archive/2008/05/27/51280.html</link><dc:creator>bon</dc:creator><author>bon</author><pubDate>Tue, 27 May 2008 07:46:00 GMT</pubDate><guid>http://www.shnenglu.com/bon/archive/2008/05/27/51280.html</guid><wfw:comment>http://www.shnenglu.com/bon/comments/51280.html</wfw:comment><comments>http://www.shnenglu.com/bon/archive/2008/05/27/51280.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bon/comments/commentRss/51280.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bon/services/trackbacks/51280.html</trackback:ping><description><![CDATA[     鎽樿: pku 1936 瑙i鎶ュ憡+LCS鐨勭悊瑙?nbsp; <a href='http://www.shnenglu.com/bon/archive/2008/05/27/51280.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/bon/aggbug/51280.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bon/" target="_blank">bon</a> 2008-05-27 15:46 <a href="http://www.shnenglu.com/bon/archive/2008/05/27/51280.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 3437http://www.shnenglu.com/bon/archive/2008/05/24/50969.htmlbonbonSat, 24 May 2008 12:34:00 GMThttp://www.shnenglu.com/bon/archive/2008/05/24/50969.htmlhttp://www.shnenglu.com/bon/comments/50969.htmlhttp://www.shnenglu.com/bon/archive/2008/05/24/50969.html#Feedback0http://www.shnenglu.com/bon/comments/commentRss/50969.htmlhttp://www.shnenglu.com/bon/services/trackbacks/50969.html闃呰鍏ㄦ枃

bon 2008-05-24 20:34 鍙戣〃璇勮
]]>
pku 3349http://www.shnenglu.com/bon/archive/2008/05/24/50937.htmlbonbonSat, 24 May 2008 03:34:00 GMThttp://www.shnenglu.com/bon/archive/2008/05/24/50937.htmlhttp://www.shnenglu.com/bon/comments/50937.htmlhttp://www.shnenglu.com/bon/archive/2008/05/24/50937.html#Feedback1http://www.shnenglu.com/bon/comments/commentRss/50937.htmlhttp://www.shnenglu.com/bon/services/trackbacks/50937.html闃呰鍏ㄦ枃

bon 2008-05-24 11:34 鍙戣〃璇勮
]]>
香蕉久久一区二区不卡无毒影院| 色偷偷88欧美精品久久久 | 久久国产乱子精品免费女| 一本久久综合亚洲鲁鲁五月天| 狠狠色综合久久久久尤物| 欧美久久精品一级c片片| 久久国产精品-久久精品| 久久电影网一区| 91精品国产91久久久久久蜜臀| 国产成人无码精品久久久免费 | 久久亚洲中文字幕精品一区| 国产午夜精品理论片久久影视| 粉嫩小泬无遮挡久久久久久| 2021久久精品国产99国产精品| 97久久超碰国产精品2021| 99久久成人国产精品免费| 久久精品国产只有精品2020| 国内精品欧美久久精品| 亚洲国产成人精品91久久久 | 亚洲愉拍99热成人精品热久久 | 久久综合狠狠综合久久激情 | 精品蜜臀久久久久99网站| 国内精品久久久久| 狠狠人妻久久久久久综合| 老男人久久青草av高清| 久久精品九九亚洲精品| 成人亚洲欧美久久久久| 久久久久免费精品国产| 97久久天天综合色天天综合色hd| 一本大道久久a久久精品综合| 久久久亚洲精品蜜桃臀| 久久天天躁狠狠躁夜夜2020一| 久久精品国产久精国产思思| 精品国产婷婷久久久| 久久久久AV综合网成人| 久久精品国产亚洲精品| 久久精品中文字幕无码绿巨人| 国产美女久久久| 久久久久久久综合狠狠综合| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 人妻无码αv中文字幕久久|