Name: ________________________________

Honor Code Acknowledgment: ___________________


CPS 100, Spring 1997, Quiz 3

Due: January 28

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 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 (no header node).

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 (3 points)

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.

Part A 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.





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





Owen L. Astrachan
Last modified: Mon Jan 27 10:36:05 EST