锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久一区二区三区国产精品,国产精品九九,久久精品国产一区二区三区http://m.shnenglu.com/bon/zh-cnSun, 24 Aug 2025 14:12:36 GMTSun, 24 Aug 2025 14:12:36 GMT60merge sort pitfallshttp://m.shnenglu.com/bon/archive/2009/04/30/81561.htmlbonbonThu, 30 Apr 2009 05:57:00 GMThttp://m.shnenglu.com/bon/archive/2009/04/30/81561.htmlhttp://m.shnenglu.com/bon/comments/81561.htmlhttp://m.shnenglu.com/bon/archive/2009/04/30/81561.html#Feedback0http://m.shnenglu.com/bon/comments/commentRss/81561.htmlhttp://m.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://m.shnenglu.com/bon/archive/2008/07/31/57589.htmlbonbonThu, 31 Jul 2008 02:51:00 GMThttp://m.shnenglu.com/bon/archive/2008/07/31/57589.htmlhttp://m.shnenglu.com/bon/comments/57589.htmlhttp://m.shnenglu.com/bon/archive/2008/07/31/57589.html#Feedback0http://m.shnenglu.com/bon/comments/commentRss/57589.htmlhttp://m.shnenglu.com/bon/services/trackbacks/57589.html闃呰鍏ㄦ枃

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

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

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

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

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

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

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

bon 2008-05-24 11:34 鍙戣〃璇勮
]]>
国内精品久久久久| 久久精品中文字幕第23页| 97精品国产97久久久久久免费| 亚洲国产香蕉人人爽成AV片久久 | 欧美国产成人久久精品| 久久久久久精品久久久久| AV狠狠色丁香婷婷综合久久 | 香港aa三级久久三级老师2021国产三级精品三级在 | 久久亚洲精品无码播放| 亚洲中文字幕无码久久精品1| 久久er国产精品免费观看2| 久久精品综合网| 久久久久亚洲精品无码网址| 久久国产高潮流白浆免费观看| 亚洲精品NV久久久久久久久久| 久久se精品一区精品二区| 久久综合国产乱子伦精品免费| 久久久久这里只有精品 | 久久人做人爽一区二区三区 | 99久久国产综合精品网成人影院| 国内精品综合久久久40p| 无码任你躁久久久久久| 国产精品日韩深夜福利久久| 99久久er这里只有精品18| 久久精品一本到99热免费| 亚洲精品NV久久久久久久久久 | 亚洲αv久久久噜噜噜噜噜| 亚洲欧洲精品成人久久曰影片| 伊人久久大香线焦综合四虎| 久久久久一区二区三区| 久久久久亚洲AV无码麻豆| 中文字幕日本人妻久久久免费| 一本综合久久国产二区| 亚洲国产成人精品91久久久 | 人妻少妇久久中文字幕一区二区| 漂亮人妻被中出中文字幕久久| 久久综合偷偷噜噜噜色| 久久久久se色偷偷亚洲精品av| 久久久久亚洲AV无码专区首JN| 综合网日日天干夜夜久久| 国产Av激情久久无码天堂|