C # sorted by LinkedList

It seems I cannot find the C # suite (C # 3.0 that I use Unity3D) I need:

  • I need to be able to quickly add and remove elements on repeat , as in LinkedList .
  • I need to sort it often several times, e.g. Sort in a List (interested in any merge, quicksort and radixsort)
  • I need to sort according to different sorting functions , because I have to sort according to different fields like Name, Surname, etc. (therefore, SortedList or SortedDictionary not appropriate).

The list seems to be “almost correct”, except that it is actually an array, and I cannot delete items randomly, iterating forward.

A LinkedList would be ideal, but the ability to sort by mistake (for a linked list it would be a natural merge, which, in addition, is stable, it might be required to be stable, not required at the moment).

It would be best to find that, in fact, the .NET sorting method already exists for LinkedList, and I don't know about that.

If I had time to implement such a class, I would go for a LinkedList with a sorting method using mergesort and a custom lambda as a comparison, however it seems that there is no material in .NET.

0
unity3d
Aug 19 '15 at 17:29
source share
1 answer

Linq!

  • I need to be able to add and remove elements quickly, iterate, as in LinkedList.

use linq collection.RemoveAll(item => {conditions} );

  1. I need to sort it several times, for example Sort in a list (interested in any of the mergers, quick sort, and radixsort).

use linq .OrderBy(item => item.Field).ThenBy(item => item.OtherField).ThenByDescending(item => item.OmgAnotherField);

  1. I need to sort by different sorting functions, because I have to sort according to different fields like Name, Surname, etc. (so SortedList or SortedDictionary is not suitable).

see # 2

+2
Aug 19 '15 at 17:55
source share



All Articles