Name: ________________________________

Honor Code Acknowledgment: ___________________


Random Quiz # 2

CPS 100, Spring 1996

Due: January 22


Problem 1 rec.list.linked: (2 points)

Describe what list represents after the call list = Build(7); where the function Build is defined below.

struct Node
{
    int info;
    Node * next;
};

Node * Build(int num)
// postcondition: returns a linked list ????
{
    if (0 == num)
    {
        return 0;
    }
    else
    {
        ListNode * temp = new Node;
        temp->info = num;
        temp->next = Build(num - 1);
        return temp;
    }
}

Problem 2 C. F. Gauss: (2 points)

What is the value of the expression DoWhat(10); where the function DoWhat is given below.

   int DoWhat(int num)
   // postcondition: returns a number ???
   {
       if (0 == num) return 0;
       else return num + DoWhat(num - 1);
   }