Container Classes: List
The list provides a dynamically resizing, sequential access container for like type objects. Lists are suitable replacements for personal linked-list implementations, both sorted and un-sorted.
Usage: #include <list> and use the std namespace.
Declaration examples:
list<int> listOfIntegers;
list<char> listOfCharacters;
list<myClass> listOfMyClass; // a listof myClass objects where myClass is any user-defined class
Common member functions:
Operators: =, ==, and !=
push_front(element): Inserts an element onto the front of the list
front(): Gets the element at the head of the list
size(): Reports the number of elements in the list
clear(): Removes all elements from the list
insert(iterator, element): inserts a copy of the element before the element referenced by iterator
sort(): Sorts the list, as long at the object in the list provides a "<" operator
Example programs:
This program creates two lists of integers to demonstrate them: int_list.cpp
This program is like that above, only it create two lists of a custom class to show that lists can hold elements of any type: list.cpp