C++ Vector like class in C#
Here is a list with some C++
/ C#
containers that are roughly equivalent (not exact replacements) to each other:
std::multiset
->SortedDictionary<Tkey, int>
(int
keeping count of the number ofTkey
s)
Minas Mina
Writing code and learning new stuff is one of the things I truly enjoy! On most days of the week, after work, I work on my own projects: My most notable project is Movie Pal - An app for discovering movies Linked in My LinkedIn profile. My Apps See all of my apps in Play Store. Learning I have an interest in the following technologies: Android (Java, Kotlin) React I am currently learning Python and Machine Learning on Udemy. Languages I speak Greek and English fluently and I am learning Spanish and German on Duolingo.
Updated on June 04, 2022Comments
-
Minas Mina almost 2 years
What is the analogous class of C++
std::vector
in C#?I want a class where it keeps an internal array inside and supports insertion at the back in
O(1)
time. -
Weyland Yutani over 10 yearsstd::set - HashSet<T> ?
-
Cole Tobin over 10 yearsBut the OP wants O(1) insertion time, which doesn't exist in vector or List.
-
Weyland Yutani over 10 yearssurely vector and list are O(1) insert, doesnt say anything about sorting
-
harold over 10 yearsOP only asks for O(1) insertion at the back
-
Hamlet Hakobyan over 10 yearsList<T> have O(1) in add at the back if the size less than capacity. It s very important.
-
w128 over 10 yearsUsing
List.Add()
can become O(n) operation if capacity change is needed.LinkedList
, however, guarantees O(1) back insertion. -
harold over 10 yearsList.Add is O(1) amortized, that might count too - actually it probably does, because OP explicitly asks for an array-backed datastructure.
-
Sam over 10 years@WeylandYutani: neither
List<T>
norvector
are O(1) for all insertions (only those that happen atindex == count
, and if a resize occurs this wouldn't be the case either). -
Weyland Yutani over 10 yearsah i was confusing insert in middle with replace
-
CMircea over 9 yearsstd::set is equivalent to SortedSet; std::unordered_set is HashSet. Same for std::map.
-
Enamul Hassan about 8 yearsIf you have another question, please ask it by clicking the Ask Question button.
-
Benji Altman over 3 yearsstd::vector is not backed by a linked list, it specifically stores data contiguously in memory (like an array). Source: cplusplus.com/reference/vector/vector - second paragraph.