This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSc 17 Test 2 Friday 13 November 1998 Page 1 >>>>>>>>>>> Answers <<<<<<<<<<<<<<<<<<<<<<< 1. (15 pts) In writing the function below, I forgot to provide the documention. Provide it by stating the pre and postconditions. The function assumes the class Node, which is defined as follows: class Node{ public: int key; Node * next; }; void enigma(Node * head, int x, int &c){ if(head!=NULL){ if(head>key > x) c++; enigma(head>next,x,c); } } PRECONDITIONS: head is NULL or points to a valid node. Valid nodes either point to NULL or to a valid node. The variable c has some value, x has some value POSTCONDITIONS: c has been increased by the number of nodes whose keys exceed x. 2. (25 pts) Write a bool function, dup, such that the call dup(head) returns the value true if and only if the linked list to which head points has two consecutive keys which are equal. Assume that head is declared as Node * head, as where Node is the class defined in question 1. Of course, you can assume that the last link...
View
Full Document
 Spring '08
 varies

Click to edit the document details