Name: ________________________________ Section: _________________

Honor Code Acknowledgment: ___________________


Random Quiz # 7

CPS 100e, Fall 1995

Due: November 2


Yin/Yang (5 points)

A circularly-linked list is maintained by keeping a pointer to the last node; the first node is then the node ``after'' the last node (since the list is circular). Write two functions: Prepend that adds a new node to the front of a circularly-linked list and RemoveLast that removes the last node from a circularly-linked list.

 struct Node
 {
     int info;
     Node * next;
     Node(int value, Node * follow = 0)
     {
         info = value;
         next = follow;
     }
 };

 void Prepend(Node * list, int value)
 // precondition: list points to last node of NON-empty circularly-linked list
 //               (first node is list->next)
 // postcondition: new first node with info == value added to 
 //                the circularly-linked list whose last node is list


 void RemoveLast(Node * & list)
 // precondition: list points to last node of NON-empty circularly-linked list
 //               (first node is list->next)
 // postcondition: last node is removed (returned to heap) and list
 //                points to the new last node