Order by Different Enum Property Each Row in C# – Algorithm Guide

algorithmscorder

So I have a list of DefaultSearchModal items that have an enum called TypeSearch in every list item. I would like to order the list to have a different enum property each row.

So if you have an unordered list by this:

1,1,2,2,3,3,4,4,5,5,5,5,5,5

I would like to order it to:

1,2,3,4,5,1,2,3,4,5,5,5,5,5

What would be a good algorithm to sort it like this?

    public class DefaultSearchModel
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string Url { get; set; }
    public TypeSearch TypeSearch { get; set; }
}

public enum TypeSearch
        {
           News = 0,
           Blog = 1,
           Photo = 3,
           Page = 4
        }

Best Answer

Personally I would just put it in a loop Here's psudo code for it.

while mainList has items
{
  find first 0 item.
  add to queue, 
  remove from mailList

  find first 1 item 
  add to queue, 
  remove from mailList

  find first 3 item.
  add to queue, 
  remove from mailList

  find first 4 item.
  add to queue, 
  remove from mailList
}

return queue
Related Topic