Containers

Containers are data structures that manage collection of objects.

Array: Array is a data type that stores multiple elements of same data type. We have discussed details about arrays in previous section.

Vectors: These are dynamic arrays that can grow and shrink their size. Elements in vectors can be accessed using indexing.

Methods of Vectors

MethodDescription
push_back()It is used to push elements to a vector.
pop_back()It is used to pop elements from a vector.
capacity()It is used to check how many elements can be inserted to a vector.
size()It is used to check how many elements are there in a vector.
front()It gives the reference to the first element in a vector.
back()It gives the reference to the last element in a vector.
swap()It exchanges the elements between vector.
empty()It checks if the vector is empty or not.
clear()It removes all the elements from the vector.
resize()It modifies the size of the vector.

Deque

Deque is a short from of Double Ended Queue. It allows the insertion and deletion of elements from both ends.

Lists

List is a linear data structure that stores elements in a sequence, and each element (node) in the list contains a value and two pointers: one to the previous element and one to the next element.

Maps

Maps are containers that stores elements in key-value pairs where each key is unique.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which of the following is a best practice in programming?

10 XP~2 min
Exercise 2 of 2Easy

Code that is easy to read and understand is called ___ code.

10 XP~2 min