We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Tag: Vector

Remove all occurences of an element from vector in O(n) complexity

Suppose we have a vector of integers and we want to delete all occurences of a number from it i.e. Let’s say vector contain following numbers 1,2,5,4,5,1,5,7,8,9. Now we want to delete all the occurences of 5 from it, so that vector contents should become – 1 2 4 1 7 8 9 . Also …

Remove all occurences of an element from vector in O(n) complexityRead More

How to use vector efficiently in C++?

We can use vector efficiently by taking care of following points, 1.) Vector will be more efficient if elements are inserted or removed from the back-end only. Advertisements As, vector internally stores all the elements in consecutive memory location. Therefore, if an element is added in middle, then vector right shifts all the right side …

How to use vector efficiently in C++?Read More

deque vs vector : What to choose ?

In this article we will discuss the differences between vector and deque STL Containers. Vector provides insertion and deletion at middle and end only. Whereas, deque provides operations for insertion at front, middle and end. That is, apart from push_back() and pop_back() APIs jus like vector, deque also has push_front() and pop_front() API to add …

deque vs vector : What to choose ?Read More

Different Ways to Initialize a vector in C++

In this article we will discuss different ways to initialize a std::vector in C++. Initializing std::vector elements with same value std::vector<int> vec_1(5, 10); It will create a vector of 5 element and initialize  each element is initialized to 10. Advertisements Initializing std::vector elements with passed argument list std::vector<int> vec_2 = {10,20,30,40,50}; It will create a vector of 5 …

Different Ways to Initialize a vector in C++Read More

5 Different ways to Initialize a vector in c++

In this article we will discuss different ways to initialize a vector in C++. Creating a vector object without any initialization will create an empty vector with no elements i.e. Advertisements std::vector<int> vecOfInts; But we generally want to initialize a vector with huge values and calling push_back() that many times to add element in vector is not an …

5 Different ways to Initialize a vector in c++Read More

How to fill a vector with random numbers in C++

In this article we will discuss how to fill a std::vector with random numbers using std::generate. For this task we will use a STL algorithm std::generate i.e. Advertisements template<typename _FIter, typename _Generator> void generate(_FIter start, _FIter end, _Generator gen); It will update all the elements from range start to end -1 with values generated by …

How to fill a vector with random numbers in C++Read More

Difference between Vector and List in C++

linkedlist

In this article we will discuss the differences between std::vector and std::list in C++. Both vector and list are sequential containers of C++ Standard Template Library. But there are many differences between them because of their internal implementation i.e. Advertisements List stores elements at non contiguous memory location i.e. it internally uses a doubly linked …

Difference between Vector and List in C++Read More

Cart

Your Cart is Empty

Back To Shop