T
- Type of elements.
Return: none
Arguments: T
Pushes element with a given value to the front.
Return: none
Arguments: T
Pushes element with a given value to the back.
Return: none
Arguments: none
Removes element from the front.
Return: none
Arguments: none
Removes element from the back.
Return: T
Arguments: none
Returns front element.
Return: T
Arguments: none
Returns back element.
Return: unsigned int
Arguments: none
Returns size of the list.
Return: bool
Arguments: none
Returns whether the list is empty.
Return: iterator
Arguments: none
Returns iterator object to the front element.
Return: iterator
Arguments: none
Returns iterator object to past the back element.
Library include
#include "path/to/Basic-Data-Structures/include/list"
List declaration
List<int> l;
Basic push_front
, push_back
, pop_front
, pop_back
, front
and back
usage
l.push_front(3); // list: 3
l.push_front(2); // list: 2 3
l.push_back(4); // list: 2 3 4
l.push_back(5); // list: 2 3 4 5
l.push_front(1); // list: 1 2 3 4 5
std::cout << l.front() << "\n"; // prints 1
std::cout << l.back() << "\n"; // prints 5
l.pop_front(); // list: 2 3 4 5
l.pop_back(); // list: 2 3 4
l.pop_front(); // list: 3 4
std::cout << l.front() << "\n"; // prints 3
std::cout << l.back() << "\n"; // prints 4
Print list using empty
, front
and pop_front
while(!l.empty()) {
std::cout << l.front() << "\n";
l.pop_front();
}
Print stack using iterator
(recommended way)
for(List<int>::iterator i = l.begin(); i != l.end(); ++i) {
std::cout << *i << "\n";
}
Print list using iterator
with range-based for loop
and auto
(recommended way for C++11 and higher)
for(auto i : l) {
std::cout << i << "\n";
}