INFO
Sequence containers that organizes data sequentially in the order that it is added. List is different than Vectors is that it is implemented with Doubly Linked List (DLL)
- Does not have random access1
slist- Implemented as Singly Linked List (SLL)
- Not standard and not all compilers support it
Constructors
Default Constructor
list<int> list1;Fill Constructor
list<int> list2(4, 100); // 4 ints of value 100Range Constructor
list<int> list3(list.begin() + 5, list.end()); // same content as list except for the first 5 elementsCopy Constructor
list<int> list4(list); // a copy of listMember Functions
list::push_front(const T& value): Add new element to the frontlist::pop_front(): Remove the front elementlist::reverse(): reverse the order of elementslist::sort(): sort the container in ascending orderlist::remove(const T& value): delete a given element in the listlist::splice(): Transfers elements fromotherListinto the container, inserting them atposition. Effectively removes the elements fromotherListand alter the size of both containerslist::splice(const_iterator position, list& otherList)position: Position within the container where the elements ofotherListare insertedotherList: A list of object of the same type
list::splice(const_iterator position, list& otherList, const_iterator first, const_iterator last)position: Position within the container where the elements ofotherListare insertedotherList: A list of object of the same typefirstandlast: range of elements inotherList
list::merge(list& otherList): remove all elements fromotherListand insert them to the container in ascending order
Footnotes
-
The ability to retrieve or modify any element in a Data Structure directly, without needing to traverse other elements ↩