Name: ________________________________

Honor Code Acknowledgment: ___________________


Random Quiz # 6

CPS 100E, Fall 1996

Due: October 29


Problem 1 Spivey's Corners: (2 points)

Describe what the function Chop, shown below, does to the parameter list (assume list is a "standard" struct for implementing linked lists of integers).

void Chop(Node * & list) { if (list != NULL) { Chop(list->next); if (list->info % 2 == 0) { list = list->next; } } }

Problem 2: Big Fix (4 points)

What is the value of the following postfix expressions?
            8 5 + 3 2 * - 7 *
and
            22 8 12 7 + * - 10 /

Problem 3: Circle of Friends (4 points)

In a circularly linked list, the last node points at the first node (instead of at 0). Access to the list is via a pointer to the last node, since the first node is easy to get to from the last node. Write a function Prepend that adds a new node as the first node of a non-empty, circularly linked list. For an extra point deal with an empty list too.

The call Prepend(list,7) should add a node with 7 as the info field as the first node of list.

















Problem 4: Jouez Hautbois (4 points)

Part A

Consider a list of integers in which the integers are stored in non-decreasing order and in which the integer k occurs exactly k times; these lists are called N-lists where N is the largest integer in the list. For example, a 4-list is (1,2,2,3,3,3,4,4,4,4) and a five list is a 4-list with (5,5,5,5,5) appended to the end.

Using big-Oh notation (in terms of N) what is the number of elements in an N-list? Justify your answer briefly.







Part B

If all occurrences of numbers less than N/2 are removed from an N-list, how many numbers are left (using big-Oh notation)? Justify your answer briefly.