• <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 閱讀(1136) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#

            久久综合国产乱子伦精品免费| 国内精品九九久久精品| 浪潮AV色综合久久天堂| 久久免费视频网站| 久久亚洲精品无码观看不卡| 亚洲&#228;v永久无码精品天堂久久 | 日本精品一区二区久久久| 精品国产99久久久久久麻豆| 97久久国产亚洲精品超碰热| 久久九九免费高清视频| 国产激情久久久久久熟女老人| 久久婷婷五月综合97色| 久久久老熟女一区二区三区| 99久久这里只精品国产免费| 国产精品gz久久久| 久久91亚洲人成电影网站| 青青青国产精品国产精品久久久久| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 久久久久久综合一区中文字幕| 伊人久久免费视频| 精品久久久噜噜噜久久久| 国产精品女同久久久久电影院| 亚洲国产日韩综合久久精品| 狠狠狠色丁香婷婷综合久久五月 | 亚洲国产精品成人AV无码久久综合影院| 久久久精品久久久久久| 97久久久久人妻精品专区| 久久99精品久久久久久9蜜桃| 国产精品久久久天天影视| 亚洲国产成人精品91久久久| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 久久亚洲中文字幕精品一区| 久久av高潮av无码av喷吹| 免费无码国产欧美久久18| 欧美综合天天夜夜久久| 国产毛片欧美毛片久久久| 久久综合色区| 欧美色综合久久久久久| 国产A级毛片久久久精品毛片| 久久国产精品无码HDAV| 亚洲精品国产自在久久|