Name (print): ________________________________

Honor Code Acknowledgment: _____________________________


Random Quiz 4

CPS 100, Fall 1996

8 points

Due: October 1


Problem 1: Iteration (3 pts)

Write a nonrecursive function called RemoveEveryThird which removes every third node of a linked list.

Let each item in the list be represented by the struct Node:

struct Node
{
   string name;
   Node * next;
};

For example, consider the following list:

RemoveEveryThird(names) returns 2 and the list names is modified to look like:

Calling RemoveEveryThird(names) again returns 2 and the list names is modified to look like:

Complete the function RemoveEveryThird below.

int RemoveEveryThird(Node * list)
// postcondition: Removes every third node from list and returns the 
//                number of nodes removed. If the list has two or fewer
//                nodes, no nodes are removed and 0 is returned. 
{

Problem 2: Recursion (3 points)

Write a recursive version of RemoveEveryThird using the same header as above.

Problem 3: How fast does it take? (2 points)

Assume list has N nodes.