我試圖排序元素的Dictionary<int,Elem>
/SortedList<int,Elem>
時遇到問題。c#元素排序
我應該出現在列表上X
倍,但 如果一個元素是i
指數則無法i - 1
或i + 1
再現N
元素的列表。我也必須尊重名單限制(elem N在elem 1之前,elem 1在elem N旁邊)。
我有兩個可能的出發點:
其具有
Times
屬性,其具有元件應該出現在結果列表上的次數的元素的列表。示例輸入:
List<elem> elements = new List<elem>(){new Elem("star", 3), new Elem("square", 2), new Elem("circle", 3)}; //Elem construct take element name, and number of times on result list
列表,包含所有我要排序,顯然的元素,在一unssorted方式。
List<elem> elements = new List<elem>(){new Elem("star"),new Elem("star"),new Elem("star"),new Elem("circle"),("circle"),("circle"),new Elem("sqare"),new Elem("sqare")};
預期輸出:
star circle star sqare circle sqare star circle
// or any other combination in which any element is not preceded by itself
更好的性能排序算法的歡迎,但這裏不是必須的,因爲這將是很少進行。
我正在使用C#4.0和.Net Framework 4.0。
我完全不理解這個問題。也許有幾個例子會說明你正在嘗試做什麼。你能否給這些輸入提供一些示例輸入和預期輸出? – 2010-01-26 17:42:16
在沒有這種排序的情況下會發生什麼?例如,「星星星圈」沒有這樣的順序。 – jason 2010-01-26 18:17:00
在這種情況下,應該拋出異常:NoSortingPosibleException或類似的東西,但這很容易通過使用max(elem.times)* 3
2010-01-26 18:28:53