Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Vector like class in C#

Tags:

c++

c#

list

vector

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.

like image 240
Minas Mina Avatar asked Sep 19 '13 13:09

Minas Mina


People also ask

What is equivalent of vector in C?

There is no C standard equivalent to the c++ vector, though you could create a struct based off of the vector in c++. The struct would. Resize itself if the array bounds are passed the max size. perform the operations similar to that of a vector.

Is vector same as array in C?

Difference between std::vector and std::array in C++Vector is a sequential container to store elements and not index based. Array stores a fixed-size sequential collection of elements of the same type and it is index based. Vector is dynamic in nature so, size increases with insertion of elements.

How do you create a class vector?

Program to create Custom Vector Class in C++ int push_back(data): adds an element(of any data_type) to the end of array and also returns the number of elements in that vector. data_type pop_back(): removes an element from the end of array, also returns the popped element.

Is there any vector in C?

Vectors are a modern programming concept, which, unfortunately, aren't built into the standard C library. Vectors are same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container.


1 Answers

Here is a list with some C++ / C# containers that are roughly equivalent (not exact replacements) to each other:

  • std::vector -> List<T>

  • std::list -> LinkedList<T>

  • std::map -> SortedDictionary<Tkey, Tvalue>

  • std::set -> SortedSet<T>

  • std::unordered_set -> HashSet<T>

  • std::multiset -> SortedDictionary<Tkey, int> (int keeping count of the number of Tkeys)

  • std::unordered_map -> Dictionary<TKey, TValue>

like image 74
Natan Streppel Avatar answered Sep 23 '22 14:09

Natan Streppel