• <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://m.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 閱讀(1106) 評論(0)  編輯 收藏 引用 所屬分類: C#

            99久久精品国内| 一本色道久久综合狠狠躁| 狠狠色丁香久久婷婷综合五月| 中文无码久久精品| 精品久久久久久成人AV| 久久久艹| 久久久久久九九99精品| 激情久久久久久久久久| 亚洲中文字幕无码久久精品1 | 精品久久久久久久久久中文字幕| 久久无码AV中文出轨人妻 | 亚洲AV日韩精品久久久久| 日韩精品久久无码中文字幕| 久久99精品久久久久久噜噜| 99久久做夜夜爱天天做精品| 欧美亚洲国产精品久久蜜芽| 天天躁日日躁狠狠久久| 日韩久久久久中文字幕人妻| 久久国产精品-久久精品| 中文字幕久久久久人妻| 四虎国产精品成人免费久久| 日本久久久精品中文字幕| 亚洲AV无码久久| 亚洲va久久久噜噜噜久久狠狠| 久久成人永久免费播放| 国产精品久久久久9999高清| 久久久久久久久久久久中文字幕 | 色欲综合久久躁天天躁| 久久精品国产亚洲麻豆| 国产精品9999久久久久| 久久人人爽人人爽人人片AV高清| 久久国产精品免费一区| 亚洲天堂久久精品| 久久久久中文字幕| 国产女人aaa级久久久级| 66精品综合久久久久久久| 久久中文字幕一区二区| 爱做久久久久久| 很黄很污的网站久久mimi色| 久久精品国产精品亜洲毛片| 人妻精品久久久久中文字幕|