pop and push Member Functions
The STL list container has member functions named pop_back , pop_front , push_back , and push_front , as described in Table Modify the linked list class that you created in Programming Challenge 1 (or the LinkedList template presented in this chapter) by adding your own versions of these member functions.
Table
Member Function | Examples and Description |
back | cout ≪ list.back() ≪ endl; The back member function returns a reference to the last element in the list. |
empty | if (list.empty()) The empty member function returns true if the list is empty. If the list has elements, it returns false . |
end | iter = list.end(); end returns a bidirectional iterator to the end of the list. |
erase | list.erase(iter); list.erase(firstIter, lastIter) The first example causes the list element pointed to by the iterator iter to be removed. The second example causes all of the list elements from firstIter to lastIter to be removed. |
front | cout ≪ list.front() ≪ endl; front returns a reference to the first element of the list . |
insert | list.insert(iter, x) The insert member function inserts an element into the list . This example inserts an element with the value x , just before the element pointed to by iter. |
Merge | list1.merge(list2); merge inserts all the items in list2 into list1. list1 is expanded to accommodate the new elements plus any elements already stored in list1. merge expects both lists to be sorted. When list2 is inserted into list1, the elements are inserted into their correct position, so the resulting list is also sorted. |
pop_back | list.pop_back(); pop_back removes the last element of the list. |
pop_front | list.pop_front(); pop_front removes the first element of the list. |
push_back | list.push_back(x); push_back inserts an element with value x at the end of the list. |
push_front | list.push_front(x); push_front inserts an element with value x at the beginning of the |
reverse | list.reverse(); reverse reverses the order in which the elements appear in the list. |
Size | Returns the number of elements in the list . |
Swap | list1.swap(list2) The swap member function swaps the elements stored in two lists. For example, assuming list1 and list2 are lists, this statement will exchange the values in the two lists. |
Unique | list.unique(); unique removes any element that has the same value as the element before it. |
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.