I have to rotate item types to make a list.
In my basic list, I have this:
Group - Type
Group 1 - 1
Group 2 - 2
Group 3 - 1
Group 4 - 1
Group 5 - 1
Group 6 - 2
Group - 7 - 3
And I want to reconstruct things like this:
Group 1 - 1
Group 2 - 2
Group 7 - 3
Group 3 - 1
Group 6 - 2
Group 7 - 3
Group 4 - 1
Group 2 - 2
Group 7 - 3
Group 5 - 1
Group 6 - 2
Group 7 - 3
Understand? Based on the type count with more items, I need to make alternate with other items.
This algorithm requires Anglogue N type.
I'm losing a little, can someone help me? What kind of algorithm does this have to do?
This is my fist pouch, though I 'm convinced that this can be improved :
Public stable IEnumerable & lt; TSource & gt; Optional group & lt; TSource, TKey & gt; (This IEnumerable & lt; TSource & gt; list, Func & lt; TSource, TKey & gt; Key selector) {var groups = list.GroupBy (keySelector). Orderbidesc (g = & gt; g.Count ()); Var largest group = group.first (); Var arrays = groups.Skip (1). Choose (G = & gt; G. Toure ()); Var index = new int [arrays.Qount ()]; Foreign currency (different item in largest group) {yield returns item; Var i = 0; Forchav (an AR in ARA) {yield returns a [index [i ++] ++% a. Length]; }}} It has been written as one, which means that you can call it like this:
var input = New {group = "group 1", type = 1}, new {group = "group2", type = 2}, new {group = "group 3", type = 1}, new {group = New {group = "Group7", type = 3}, "group 4", type = 1}, new {group = "group 5", type = 1}, new {group = "group 6", type = 2} ,}; Var results = input Optional group (x = & gt; x.Type); // groups 1 1 // groups 2 2 / group 7 3 // groups3 1 / group 6 2 / group 7 3 // groups4 1 // groups2 2/group73/group51/group6 2 / Group 7 3
No comments:
Post a Comment