C#排序的LinkedList [英] C# sorted LinkedList

查看:156
本文介绍了C#排序的LinkedList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我找不到我需要的C#(我正在使用Unity3D的C#3.0)集合:

It seems I'm not able to find the C# (C# 3.0 I'm using Unity3D) collection I need:

  1. 我需要能够像在LinkedList中一样,快速在迭代过程中快速添加和删除项目.
  2. 我需要多次对其进行排序,就像List中的Sort(对mergesort,quicksort和radixsort感兴趣)
  3. 我需要根据不同的排序功能进行排序,因为我必须根据不同的字段(例如名称,姓氏等)进行排序(所以SortedListSortedDictionary不好).
  1. I need to be able to add and remove items quickly while iterating like in a LinkedList.
  2. I need to sort it frequently several times like Sort in List (interested in any of mergesort, quicksort and radixsort)
  3. I need to sort according to different sort functions because I have to sort according to different fields like Name, Surname etc. (so SortedList or SortedDictionary no good).

列表,似乎实际上是一个数组,几乎是正确的",我无法在向前迭代时随机删除项目.

List, seems "almost correct" apart the fact it is in reality an array and I cannot remove items randomly while iterating forward.

LinkedList将是完美的,但是缺少排序功能(因为链表将是自然的mergesort,另外它是稳定的,可能需要将其作为稳定的排序,现在不需要).

LinkedList would be perfect but miss sorting ability (for a linkedlist would be natural mergesort, wich is in addition stable, may need it to be a stable sort, not required for now).

最好的选择是发现LinkedList实际上已经存在一种.NET排序方法,而我对此并不了解.

The best bet would be finding that actually a .NET sorting method already exists for LinkedList and I'm not aware of it.

如果我自己有时间实现此类,我会去一个LinkedList,它带有一种使用mergesort和自定义lambda作为比较器进行排序的方法,但是.NET似乎缺少东西了?

If I would have time of implementing such class myself I would go for a LinkedList with a method for sorting using a mergesort and a custom lambda as comparer, however seems that stuff is missing from .NET?

推荐答案

Linq!

  1. 我需要能够像在LinkedList中一样快速地添加和删除项目.

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

  1. 我需要像在列表中排序"(对mergesort,quicksort和radixsort中的任何一个感兴趣)那样频繁地对其进行几次排序

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

  1. 我需要根据不同的排序功能进行排序,因为我必须根据不同的字段(例如姓名,姓氏等)进行排序(因此 SortedList或SortedDictionary不好).
  1. I need to sort according to different sort functions because I have to sort according to different fields like Name, Surname etc. (so SortedList or SortedDictionary no good).

请参阅#2

这篇关于C#排序的LinkedList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆