cs114mid0806

cs114mid0806 - CS 114 Midterm Examination Name_ 1) Assume...

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

View Full Document Right Arrow Icon
CS 114 Midterm Examination Name___________________________________________________ 1) Assume you have a Queue class that provides the following public methods: void insert(Object x) // inserts x at back of queue. Object remove() // removes and returns Object at front // of queue. Object peek() // returns reference to Object at front // of queue without removing it. int size() // returns number of Objects in queue. The class Stack will implement a stack using the queue. Let the top of the stack always be at the back of the queue, so the bottom of the stack will be at the front of the queue. Fill in the implementations of the methods in the class below: class Stack { private Queue Q; // the queue that stores the data. public Stack(){Q = new Queue();} public void push(Object data) { } // assume the stack is not empty when pop is called public Object pop() { } }
Background image of page 1

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

View Full DocumentRight Arrow Icon
2) Suppose you have a linked list class that provides the following methods: LinkList() // constructor. int size();
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/21/2009.

Page1 / 5

cs114mid0806 - CS 114 Midterm Examination Name_ 1) Assume...

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

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