• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            bon

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              46 Posts :: 0 Stories :: 12 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(2)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            2009年4月30日 #

            Recently, I began to peruse the CLRS (Introduction to Algorithms).

            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;
            }

            posted @ 2009-04-30 13:57 bon 閱讀(258) | 評論 (0)編輯 收藏

            2008年7月31日 #

                 摘要: 未完  閱讀全文
            posted @ 2008-07-31 10:51 bon 閱讀(301) | 評論 (0)編輯 收藏

            2008年7月28日 #

                 摘要: 水題  閱讀全文
            posted @ 2008-07-28 16:48 bon 閱讀(483) | 評論 (0)編輯 收藏

            2008年7月25日 #

                 摘要: 詳細介紹KMP算法以及POJ上的一道題目  閱讀全文
            posted @ 2008-07-25 11:45 bon 閱讀(400) | 評論 (0)編輯 收藏

            2008年7月9日 #

                 摘要: kddcup08 (1)  閱讀全文
            posted @ 2008-07-09 09:55 bon 閱讀(717) | 評論 (0)編輯 收藏

            2008年6月29日 #

            最近在Wei的指導下,跟顯露參加了KDDCUP08的數據挖掘比賽。在這次比賽中的數據處理、算法以及其它的收獲,會以連載的方式發出來,敬請各位關注。
            posted @ 2008-06-29 10:52 bon 閱讀(1184) | 評論 (1)編輯 收藏

            2008年6月9日 #

                 摘要: 解題報告 rather tricky  閱讀全文
            posted @ 2008-06-09 15:29 bon 閱讀(606) | 評論 (0)編輯 收藏

            2008年5月27日 #

                 摘要: pku 1936 解題報告+LCS的理解  閱讀全文
            posted @ 2008-05-27 15:46 bon 閱讀(787) | 評論 (0)編輯 收藏

            2008年5月24日 #

                 摘要: 遞歸 樹的深度 左兒子右兄弟  閱讀全文
            posted @ 2008-05-24 20:34 bon 閱讀(511) | 評論 (0)編輯 收藏

                 摘要: hash表  閱讀全文
            posted @ 2008-05-24 11:34 bon 閱讀(1087) | 評論 (1)編輯 收藏

            Google PageRank 
Checker - Page Rank Calculator
            久久久久噜噜噜亚洲熟女综合| 亚洲美日韩Av中文字幕无码久久久妻妇 | 久久综合给合久久狠狠狠97色| 老色鬼久久亚洲AV综合| 久久成人国产精品二三区| 久久久精品视频免费观看| 国产A级毛片久久久精品毛片| 69久久精品无码一区二区| 久久久久无码国产精品不卡| 日日噜噜夜夜狠狠久久丁香五月| 欧美久久精品一级c片片| 久久久久久久久久久精品尤物| 51久久夜色精品国产| 久久人人妻人人爽人人爽| 久久久久无码中| 久久精品国产亚洲综合色| 色偷偷偷久久伊人大杳蕉| 久久精品国产精品亚洲艾草网美妙| 无码精品久久久天天影视| 亚洲午夜无码AV毛片久久| 国产成人香蕉久久久久| 狠狠狠色丁香婷婷综合久久五月 | 久久久久人妻一区二区三区vr| 欧美久久综合九色综合| 香蕉久久夜色精品国产小说| 精品综合久久久久久888蜜芽| 伊人久久五月天| 色婷婷久久综合中文久久一本 | 欧美国产成人久久精品| 久久久久99精品成人片三人毛片| 99久久精品午夜一区二区| 婷婷国产天堂久久综合五月| 国内精品久久久久影院网站| 狠狠色丁香久久综合五月| 久久亚洲AV成人无码电影| 久久亚洲日韩看片无码| 久久精品aⅴ无码中文字字幕不卡| 人妻少妇精品久久| 亚洲欧美国产日韩综合久久| 一本大道久久东京热无码AV| 亚洲欧美成人久久综合中文网 |