Ch04 - 1.1 Draw the queue in Figure 4.3 as it will appear after the insertion of customer Harris and the removal of one customer from the queue

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1.1 Draw the queue in Figure 4.3 as it will appear after the insertion of customer Harris and the removal of one customer from the queue. Which customer is removed? How many customers are left? Original Queue (Fig 4.3) Thome Abreu Jones After insertion of Harris Thome Abreu Jones Harris After removal of customer Thome. Abreu Jones Harris 4.2 Answer Question 1 for the queue in Figure 4.5(c). Queue of Fig. 4.5(c) Dustin Robin Debbie Rich Philip After inserting Harris Dustin Robin Debbie Rich Philip Harris After removing first item (Dustin) Robin Debbie Rich Philip 2.1 Write an algorithm to display all the elements in a queue using just the queue operations. How would your algorithm change the queue? declare an integer x declare an integer y declare an object temp set x = queue.getSize() set y = 0 loop while y < x set temp = queue.remove() display temp queue.add(temp) increment y by 1 next loop This algorithm would rotate the entire queue once, but the queue would essentially be the same in the end, with the same size and order of objects. 2.2 Trace the following fragment for a Stack<String> s and an empty queue q (type Queue<String> ). String item; while (!s.empty()) { item = s.pop(); q.offer(item); } while (!q.isEmpty()) { item = q.remove(); s.push(item); } a. What is stored in stack s after the first loop executes? What is stored in queue q after the first loop executes? b. What is stored in stack s after the second loop executes? What is stored in queue q after the second loop executes? Stack s Queue q Stack s Queue q First Second Third s is not empty. After item = s.pop(); q.offer(item); Stack s Queue q Second Third First s is not empty. After item = s.pop(); q.offer(item); Stack s Queue q Third First Second s is not empty. After item = s.pop(); q.offer(item); Stack s Queue q First Second Third s is empty. q. is not empty. After item = q.remove(); s.push(); Stack s Queue q First Second Third q. is not empty. After item = q.remove(); s.push(); Stack s Queue q Second First Third q. is not empty. After item = q.remove(); s.push(); Stack s Queue q Third Second First q is empty. a. After the first loop executes the stack s is empty and the queue q contains a copy of the stack. b. After the second loop executes the stack s has its original contents in reverse order and the queue q is empty. 3.1 Show the new array for the queue in Figure 4.10 after the array size is doubled....
View Full Document

This document was uploaded on 11/01/2011 for the course COMPSCI 225 at Boise State.

Page1 / 9

Ch04 - 1.1 Draw the queue in Figure 4.3 as it will appear after the insertion of customer Harris and the removal of one customer from the queue

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