• <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>

            brent's hut

            Red Black Tree in C#

            Several weeks ago, I tried hard to search an implement of balance binary tree in C#,  what i needed was something like std::set<key, comparator> in C++: the data should be sorted, can be inserted and deleted at low cost and provides iterator which can move forward and backward. It looks like this can be easily achieved by List<T> with List<T>.Sort and List<T>.BinarySearch, the problem is that the performance of List<T> is not acceptable when the data collection size is big in my case.

            I failed to find anything that can be used directly, it is hard to believe, a lot of implement of red-black tree in Java or C++ can be easily got from internet (although none of them meets my requirement), but none in C#.

            So I had to implement one, it was translated from a C++ implement and modified to provide an immutable node.

            Source code 
            http://www.shnenglu.com/Files/aqazero/RBTree.zip
            Use at your own risk!
            Example:
             1         RBTree<int> rbt = new RBTree<int>(Comparer<int>.Default);
             2         rbt.Add(3);
             3         rbt.Add(1);
             4         rbt.Add(10);
             5         rbt.Add(6);
             6         rbt.Add(7);
             7         rbt.Remove(10);
             8         RBNode<int> node6 = rbt.GetNode(6);
             9         rbt.Remove(node6);
            10 
            11         RBNode<int> node = rbt.GetNode(3);
            12         node = node.Prev;
            13         while (null != node)
            14         {
            15             System.Diagnostics.Trace.WriteLine(node.Value);
            16             node = node.Next;
            17         }

            Output:
            1
            3
            7

            posted on 2017-04-29 05:02 brent 閱讀(1120) 評論(0)  編輯 收藏 引用 所屬分類: C#

            久久亚洲私人国产精品vA| 国产成人久久激情91| 欧美日韩精品久久久免费观看| 国产精品99久久精品爆乳| 国内精品久久久久久麻豆| 久久www免费人成精品香蕉| 欧美大战日韩91综合一区婷婷久久青草| 久久99精品久久久久久齐齐| 色婷婷噜噜久久国产精品12p | …久久精品99久久香蕉国产| 国产精品99久久精品| 精品久久久无码中文字幕| 三级三级久久三级久久| 狠狠色丁香久久综合婷婷| 香蕉99久久国产综合精品宅男自 | 亚洲国产精品18久久久久久| 精品久久人妻av中文字幕| 久久福利片| 国内精品久久久久影院优| 一本久久免费视频| 亚洲成色999久久网站| 久久久久久久精品成人热色戒| 久久99精品国产99久久| 99久久综合国产精品免费| 日本道色综合久久影院| 亚洲AV无码久久| 一本色道久久88综合日韩精品| 亚洲精品国产成人99久久| 精品国产VA久久久久久久冰| 伊人热热久久原色播放www| 一本大道久久a久久精品综合| 伊人久久大香线蕉亚洲五月天| 日本加勒比久久精品| 久久国产精品免费| 久久成人精品视频| 69久久精品无码一区二区| 浪潮AV色综合久久天堂| 亚洲精品国产字幕久久不卡 | 日本强好片久久久久久AAA| 2021最新久久久视精品爱| 亚洲精品无码久久毛片|