I have a problem trying to sort a Dictionary<int,Elem>
/SortedList<int,Elem>
of elements.
I have a list of N
elements that should appear X
times on the list, but
if an element is on i
index then it cannot reappear on i - 1
or i + 1
. I also must respect list limits (elem N is before elem 1 and elem 1 is next to elem N).
I have two possible starting points:
A list of elements which have a
Times
property, which has the number of times the element should appear on the resulting list.Example Input:
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
A list, containing all the elements I want to sort, obviously, in an unssorted fashion.
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")};
Expected output:
star circle star sqare circle sqare star circle
// or any other combination in which any element is not preceded by itself
Better performance sort algorithms are welcome but not a must here, since this will be done infrequently.
I'm using C# 4.0 and .Net Framework 4.0.