同桌上课用手指进去了好爽_欧美丰满熟妇xxⅹⅹ性大i_成人av天天日天天拍拍_猛男gay帅男gay男男同志_欧美va天堂在线观看_人妻无码av中文系列三里桃花_亚欧免费无码在线观看_久久久精品国产亚洲av水_日韩在线免费看污污污_2021无码专区人妻系列日韩

首頁(yè) 優(yōu)化推廣 C#中SortedList 和 SortedDictionary集合類型 .

C#中SortedList 和 SortedDictionary集合類型 .

來(lái)源: | 時(shí)間:2013/6/11 1:00:10 |

a:  System.Collections.Generic的SortedList

b.: System.Collections.Generic的SortedDictionary

1.a與b的作用:

           能夠存儲(chǔ)數(shù)據(jù)并自動(dòng)按照key進(jìn)行排序。

2.定義與使用:

           SortedDictionary<key,value>

           SortedList<key,value>

           其中key與排序有關(guān),value為值且可以為值或引用類型。

 

            // SortedDictionary

            SortedDictionary<int, string> sDictionary = new SortedDictionary<int, string>();
            sDictionary.Add(3, "cc");
            sDictionary.Add(4, "dd");
            sDictionary.Add(1, "aa");
            sDictionary.Add(2, "bb");            // 此處可以發(fā)現(xiàn)sDictionary已經(jīng)自動(dòng)按key進(jìn)行了排序

            //  得到SortedDictionary的所有key的集合

            SortedDictionary<int, string>.KeyCollection keys = sDictionary.Keys;

            //  得到SortedDictionary的所有value的集合
            SortedDictionary<int, string>.ValueCollection values = sDictionary.Values; 

            //SortedList

            SortedList<int, string> sList = new SortedList<int, string>();
            sList.Add(3, "cc");
            sList.Add(4, "dd");
            sList.Add(1, "aa");
            sList.Add(2, "bb");                       // 此處可以發(fā)現(xiàn)sList已經(jīng)自動(dòng)按key進(jìn)行了排序

            //  得到SortedList的所有key的集合

            IList<int> keysList = sList.Keys;

           //  得到SortedList的所有value的集合
            IList<string> valuesList = sList.Values;

3.二者區(qū)別

SortedList 泛型類是具有 O(log n) 檢索的二進(jìn)制搜索樹(shù),其中 n 是字典中元素的數(shù)目。就這一點(diǎn)而言,它與 SortedDictionary 泛型類相似。這兩個(gè)類具有相似的對(duì)象模型,并且都具有 O(log n) 的檢索運(yùn)算復(fù)雜度。這兩個(gè)類的區(qū)別在于內(nèi)存的使用以及插入和移除元素的速度:

  • SortedList 使用的內(nèi)存比 SortedDictionary 少。

  • SortedDictionary 可對(duì)未排序的數(shù)據(jù)執(zhí)行更快的插入和移除操作,它的運(yùn)算復(fù)雜度為 O(log n),而 SortedList 的運(yùn)算復(fù)雜度為 O(n)。

  • 如果使用排序數(shù)據(jù)一次性填充列表,則 SortedList 比 SortedDictionary 快。

4.與List相比的優(yōu)勢(shì)是能夠自動(dòng)排序

       List的排序請(qǐng)看另一篇文章。

服務(wù)熱線

153 8323 9821

功能和特性

價(jià)格和優(yōu)惠

網(wǎng)站和維護(hù)

推廣和優(yōu)化

微信服務(wù)號(hào)