Lists stores elements sequentially in a linked list. It allows for fast insertions and deletions compared to vectors (vectors), but random access is slower.
Assign () Assign value to list
Back () returns the last element
Begin () returns the iterator that points to the first element
Clear () Delete all elements
Empty () returns True if the list is empty
End () return iterator
Erase () deletes an element
Front () returns the first element
Get_allocator () returns the Configurator of the list
Insert () Inserts an element into the list
Max_size () returns the maximum number of elements the list can hold
Merge () merges two list
Pop_back () deletes the last element
Pop_front () deletes the first element
Push_back () Add an element at the end of the list
Push_front () Add an element to the head of the list
Rbegin () returns a reverse iterator that points to the first element
Remove () delete element from list
Remove_if () deletes elements by specified criteria
Rend () a reverse iterator that points to the end of the list
Resize () Change the size of the list
Reverse () reverse the elements of the list
Size () returns the number of elements in the list
Sort () sorting list
Splice () Merge two list
Swap () swap two list
Unique () Delete duplicate elements in the list
Example one:
[CPP] View plain copy #include <iostream> #include <list> #include <numeric> #include <algorithm> using namespace std; //Create an instance of a list container listint typedef list<int> LISTINT; //Create an instance of a list container listchar typedef list<int> listchar; void main () { //use list container to process integer data // Use Listint to create a list object named Listone LISTINT listOne; //declaration I for iterators LISTINT::iterator i; //adds data to the Listone container in the past listone.push_front (2); listOne.push_front (1); //Add data from the back to the Listone container listOne.push_back (3); listone.push_back (4); //display data from Listone in front of back cout<< "Listone.begin ()--- listone.end ():" <<endl; for (I = listone.begin (); i != Listone.end () ++i) cout << *i << " "; cout << endl; //to display data from Listone in the back of the post LISTINT::reverse_iterator ir; cout<< " Listone.rbegin ()---listone.rend (): <<endl; for (ir = Listone.rbegin () ir!=listone.rend (); ir++) { cout << *ir << " "; } cout << endl; //using STL accumulate (cumulative) algorithm Int result = accumulate (Listone.begin (), listone.end (), 0); cout<< "sum=" <<result<<endl; cout< < "------------------" <<endl; //-------------------------- //processing character data with list container //-------------------------- //use Listchar to create a list object named Listone LISTCHAR listTwo;