data structure chapter 3 exercises

2
Chapter 3: Exercises 1. If you add the objects a1, a2, and a3 to an initially empty deque, in what order will three removeFront operations remove them from the deque? 2. After the following statements execute, what are the contents of the queue? QueueInterface<String> myQueue = new LinkedQueue<String>(); myQueue.enqueue("a1"); myQueue.enqueue("a2"); myQueue.enqueue("a3"); myQueue.enqueue(myQueue.getFront()); myQueue.enqueue(myQueue.dequeue()); myQueue.enqueue("a4"); String st = myQueue.dequeue(); myQueue.enqueue(myQueue.getFront()); 3. After the following statements execute, what are the contents of the deque? DequeInterface<String> myDeque = new LinkedDeque<String>(); myDeque.addToFront("a1"); myDeque.addToFront("a2"); myDeque.addToBack("a3"); myDeque.addToBack("a4"); String st = myDeque.removeFront(); myDeque.addToBack(st); myDeque.addToBack(myDeque.getFront()); myDeque.addToFront(myDeque.removeBack()); myDeque.addToFront(myDeque.getBack()); 4. After the following statements execute, what are the contents of the queue? QueueInterface<String> myQueue = new LinkedQueue<String>(); myQueue.enqueue("Jan"); myQueue.enqueue("Feb"); myQueue.enqueue(myQueue.dequeue()); myQueue.enqueue("Mar"); myQueue.enqueue(myQueue.getFront()); 5. Assume that customerLine is an instance of the class WaitLine given in example. The call customerLine.simulate(15, 0.5, 5) produces the following random events: Customer 1 enters the line at time 6 with a transaction time of 3. Customer 2 enters the line at time 8 with a transaction time of 3. Customer 3 enters the line at time 10 with a transaction time of 1. SSK3117/sa’adah

Upload: rockers91

Post on 30-Nov-2015

75 views

Category:

Documents


5 download

DESCRIPTION

Data Structure Chapter 3 Exercises

TRANSCRIPT

Page 1: Data Structure Chapter 3 Exercises

Chapter 3: Exercises

1.If you add the objects a1, a2, and a3 to an initially empty deque, in what order will three removeFront operations remove them from the deque?

2.After the following statements execute, what are the contents of the queue?

QueueInterface<String> myQueue = new LinkedQueue<String>();myQueue.enqueue("a1");myQueue.enqueue("a2");myQueue.enqueue("a3");myQueue.enqueue(myQueue.getFront());myQueue.enqueue(myQueue.dequeue());myQueue.enqueue("a4");String st = myQueue.dequeue();myQueue.enqueue(myQueue.getFront());

3.After the following statements execute, what are the contents of the deque?

DequeInterface<String> myDeque = new LinkedDeque<String>();myDeque.addToFront("a1");myDeque.addToFront("a2");myDeque.addToBack("a3");myDeque.addToBack("a4");String st = myDeque.removeFront();myDeque.addToBack(st);myDeque.addToBack(myDeque.getFront());myDeque.addToFront(myDeque.removeBack());myDeque.addToFront(myDeque.getBack());

4. After the following statements execute, what are the contents of the queue?

QueueInterface<String> myQueue = new LinkedQueue<String>();myQueue.enqueue("Jan");myQueue.enqueue("Feb");myQueue.enqueue(myQueue.dequeue());myQueue.enqueue("Mar");myQueue.enqueue(myQueue.getFront());

5. Assume that customerLine is an instance of the class WaitLine given in example. The call customerLine.simulate(15, 0.5, 5) produces the following random events:

Customer 1 enters the line at time 6 with a transaction time of 3. Customer 2 enters the line at time 8 with a transaction time of 3. Customer 3 enters the line at time 10 with a transaction time of 1. Customer 4 enters the line at time 11 with a transaction time of 5.

During the simulation, how many customers are served, and what is their average waiting time?

SSK3117/sa’adah