问题描述
我几乎可以肯定这应该是一个重复的,但我搜索了一段时间,找不到答案。我应该在C#中使用什么来代替C ++向量和双端队列的有效即可。那是我需要effieciently支持直接索引并且还支持以有效的方式再次从一端或两端(取决于载体或双端队列情况)删除的结构。
I am almost certain this should be a duplicate but I searched for some time and could not find the answer. What should I use in C# to replace C++ vector and deque efficiently. That is I need a structure that supports direct indexing effieciently and also supports delete from one or both ends(depending on vector or deque case) again in an efficient manner.
在java的我通常使用ArrayList至少向量但C#我发现:
ArrayList的动态调整。随着元素被添加,它生长在容量来容纳它们。
这是最经常在老年C#程序中使用。那么什么是新的方式来做到这一点?并再次什么我为双端队列时怎么办?
In java I usually use ArrayList at least for vector but for C# I found this source that states:ArrayList resizes dynamically. As elements are added, it grows in capacity to accommodate them. It is most often used in older C# programs.
. So what is the new way to do this? And again what do I do for the deque case?
推荐答案
有没有可用的内置deque的容器,但有几种实现
There's no built-in Deque container, but there are several implementations available.
下面的一个好。这提供了O(1)操作指数也开头插入,并在末尾添加
Here's a good one from Stephen Cleary. This provides O(1) operations to index and also to insert at the beginning and append at the end.
C#的等同于Vector是的。索引访问是O(1),但插入或删除是O(N)。
The C# equivalent to Vector is List<T>
. Indexed access is O(1), but insertion or removal is O(N) (other than Inserting at the end, which is O(1)).
这篇关于C#相当于C ++的vector或deque的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!