Name: ________________________________ Section: _________________

Honor Code Acknowledgment: ___________________


Random Quiz # 5

CPS 100e, Fall 1995

Due: October 24


Consider the following node definition.
struct Node
{
   string info;
   Node * next;

   Node(string in_info, Node * follow = 0)
   {
      info = in_info;
      next = follow;
   }
};
Complete the function Duplicate below which replaces each node in a linked list of names with two nodes with that name. For example if first pointed to the linked list:
        first
	  |
	  v
	  "mo"  ->  "po"  -> "so" -> 0
Then after Duplicate(first), the list would look like:
        first
	  |
	  v
	  "mo" -> "mo" -> "po" -> "po" -> "so" -> "so" -> 0
void Duplicate(Node * & list)
// postcondition: list contains the names a1, a2, ... an
// postcondition: list contains the names a1, a1, a2, a2, ..., an, an