int StackSize(const Stack & s) // postcondition: returns # of elements stored in stack s { Stack copy(s); int count = 0; while (! copy.IsEmpty() ){ count++; copy.Pop(); } return count; } int operator < (const Stack & a, const Stack & b) // postcondition: returns 1 if stack a is "smaller" than stack b. { return StackSize(a) < StackSize(b); } void Insert(Node * & list, int val) // precondition: list is sorted, list = a1, a2, ..., an // postcondition: list is sorted, list contains val and all nodes a1, .... ,an { Node * node = new Node(val); // add this to list if (list == NULL){ // nothing here before list = node; } else if (list->info > val){ // goes first in list node->next = list; list->previous = node; list = node; } else{ Node * temp = list; while(temp->next && temp->next->info < val){ temp = temp->next; } if (temp->next == 0){ // goes at end of list temp->next = node; node->previous = temp; } else{ node->next = temp->next; temp->next = node; node->next->previous = node; node->previous = temp; } } } void Insert(Node * & list, int val) // precondition: list is sorted, list = a1, a2, ..., an // postcondition: list is sorted, list contains val and all nodes a1, .... ,an { Node * node = new Node(val); if (list == 0){ list = node; } else if (list->info < val){ Insert(list->next,val); } else{ node->next = list; node->previous = list->previous; list->previous = node; list = node; } } List & List::operator += (const Key & key) // precondition: *this represents a1, a2, ..., an // postcondition: *this represents a1, a2, ..., an, key { Node * temp = first; while (temp->next){ temp = temp->next; } temp->next = new Node(key); return *this; } void List::Uniquify() { Node * temp = first->next; // skip header node while(temp){ Remove(temp->next,temp->info); temp = temp->next; } }