我试图排序元素的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