c17f98t2 - CSc 17 Test 2 Friday 13 November 1998 > Answers...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 post-conditions. 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 in the list points to NULL.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern