2005_2100_Final

2005_2100_Final - CSC2100B CSC2100B DataStructures...

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

View Full Document Right Arrow Icon
CSC 2100B CSC 2100B Data Structures Data Structures Tutorial 11  Tutorial 11  Sample Questions Sample Questions 18 th  April 2006
Background image of page 1

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

View Full Document Right Arrow Icon
2 CSC2100B Practice Exam CSC2100B Practice Exam Tom correctly implements the ADTs of stacks of integer and  queues of integers. The ADT interface classes he provides are as  follow. // Stack.java   public interface Stack {   public void push(int element);   public int pop();   public int stackDepth();   public boolean isEmpty();  // Queue.java public interface Queue {   public void enqueue(int c);   public int dequeue();   public int queueLength();   public boolean isEmpty();   }  Tom also provides the implementation classes  Stack_imp  and  Queue_imp  respectively.
Background image of page 2
3 1 1 (10 marks)  Using Tom’s implementation, write a method public Queue reverseQueue(Queue q) that returns a Queue object that is the reverse of the argument. You should make use ONLY ONE stack The contents of the argument queue should NOT have been  changed.
Background image of page 3

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

View Full Document Right Arrow Icon
4 public Queue reverseQueue(Queue queue) {     Stack stack  = new Stack_imp();      Queue revQueue = new Queue_imp();     char value; if (queue.isEmpty()) return revQueue; while (!queue.isEmpty()) stack.push(queue.dequeue()); while (!stack.isEmpty()) {      value = (char) stack.pop();      revQueue.enqueue(value);       queue.enqueue(value);
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '06
  • CJYuan
  • Nontotient, public int pop, Public Interface, public interface Queue, public List append, public int dequeue

{[ snackBarMessage ]}

Page1 / 19

2005_2100_Final - CSC2100B CSC2100B DataStructures...

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

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