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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

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

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 4

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online