CSE
c17f97f

# c17f97f - CSc 17 Final Examination Monday 15 December 1997...

• Notes
• nizhes
• 4

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

CSc 17 Final Examination Monday 15 December 1997 4 PM >>>>>>>>>>>>>>>>>>>>>ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< CLOSED BOOK, CLOSED NOTES. ANSWERS AVAILABLE AFTER THE TEST ON MY WEB PAGE AND ON THE BULLETIN BOARD CSCKAY 1. (20 pts) Suppose we have a class called Stack whose instances implement a stack of floats in the usual way and whose member functions include bool empty(), void push(float x), and float pop(). Write a member function swap() which exchanges the top two entries if there are two or more entries on the stack and which leaves the stack alone if there is one or no entry on the stack. >>>>>>>>>>>>>>>>>> void Stack::swap() {float top,next; if (!empty()) {top=pop(); if (empty()) push(top); else {next=pop(); push(top); push(next); } } } >>>>>>>>>>>>>>>>>>> 2. (15 pts) Starting with an empty binary tree, draw a picture of the tree after each of the numbers 12, 4, 8, 6, 9, 7, 18, 22 is entered into the tree, in that order, where a) the tree is used to sort the data in ascending order b) the tree is maintained as a heap >>>>>>>>>>>>>>>>>>>>>>>> a) 12 --> 12 --> 12 --> 12 --> 12 --> 12 --> 12 --> 12 / / / / / / \ / \ 4 4 4 4 4 4 18 4 18 \ \ \ \ \ \ \ 8 8 8 8 8 8 22 / / \ / \ / \ / \ 6 6 9 6 9 6 9 6 9 \ \ \ 7 7 7 b) 12 --> 12 --> 12 --> 12 --> 12 --> 12 --> 18 --> 22 / / \ / \ / \ / \ / \ / \ 4 4 8 6 8 9 8 9 8 9 12 18 12 / / \ / \ / / \ / \ / \ / \ 4 4 6 4 6 7 4 6 7 8 9 6 7 8 / 4 >>>>>>>>>>>>>>>>>>>>>>> 3. (20 pts) In some applications, we want to have very long integers, say with a few hundred digits, but C++ limits us to about 10 digits. Write the specifications for an Abstract Data Type (ADT) for VeryLongIntegers.

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

This is the end of the preview. Sign up to access the rest of the document.
• Spring '08
• varies
• pts, Design by contract, Postcondition, VeryLongInteger

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern