added functions to be used in lists (#18541)

This commit is contained in:
Shaurya Vardhan Singh
2018-10-14 22:02:14 +05:30
committed by Quincy Larson
parent 8b1c33e704
commit bcd9eaf92f

View File

@ -12,8 +12,22 @@ whose job is to maintain the order of the list elements kind of like the link be
of how Lists are organized compared to Vectors and Arrays. of how Lists are organized compared to Vectors and Arrays.
![img](https://imgur.com/SiU8uTe.png) ![img](https://imgur.com/SiU8uTe.png)
Traversal in a list is slow as compared to Vectors and Arrays, but once a position has been found, insertion and deletion are quick.
## How to declare a List ## How to declare a List
If you want to declare a List of Numbers you write: If you want to declare a List of Numbers you write:
'''std::list<int> Numbers;''' '''std::list<int> Numbers;'''
## Functions used with List
size() : Returns the number of elements in the list
begin() : Returns an iterator pointing to the first element of the list
end() : Returns an iterator pointing to the theoretical last element which follows the last element
push_front(data) Adds a new element with value 'data' at the beginning of the list
push_back(data) Adds a new element with value 'data' at the end of the list
pop_front() Removes the first element of the list
pop_back() Removes the last element of the list
## How to use these Functions
Numbers.size();