Wednesday 25 July 2012

list Library

<list>


A list is like a deque but optimized for insert and erase at any point at the cost of random access. It lacks [] (indexing), and its iterators are bidirectional, not supporting [], +, -, <, >, <=, or >=. list adds v.splice(d, v2, b); // Move *b from list v2 to in front of d in v
v.splice(d, v2); // Move all elements of list v2 to in front of d in v
v.splice(d, v2, b, e); // Move [b,e) in v2 to in front of d at v
v.remove(x); // Remove all elements equal to x
v.remove_if(f); // Remove elements x where f(x) is true
v.sort(); // Sort list
v.sort(f); // Sort list using function bool f(x,y) instead of x < y
v.merge(v2); // Merge sorted list v2 into sorted list v
v.merge(v2, f); // Merge using f(x,y) instead of x < y to sort v
v.unique(); // Remove duplicates from sorted list
v.unique(f); // Use f(x,y) instead of x == y
v.reverse(); // Reverse order of elements
Iterators can only be moved one element at a time using ++ or --, and compared using == or !=. char* cp="ABCDE";
list<char> v(cp, cp+5); // v.size() is 5
for (list<char>::const_iterator p=v.begin(); p!=v.end(); ++p) // Print ABCDE
cout << *p;

No comments:

Post a Comment