CHAPTER 3
Lists, Stacks, and Queues
3.1
template <typename Object>
void printLots(list <Object> L, list<int> P)
{
typename list < int > ::const_iterator pIter ;
typename list < Object >::const_iterator lIter ;
int start = 0;
lIter = L.begin();
3.2 (a) Here is the code for single linked lists:
// beforeP is the cell before the two adjacent cells that are to be
// swapped
// Error checks are omitted for clarity
void swapWithNext(Node * beforep)
}
(b) Here is the code for doubly linked lists:
// p and afterp are cells to be switched. Error checks as before
{
Node *beforep, *afterp;
beforep = p–>prev;
afterp = p–>next;
p->next = afterp–>next;
3.3
template <typename Iterator, typename Object>
Iterator find(Iterator start, Iterator end, const Object& x)
{
Iterator iter = start;