QueueStack - Queue&Stack 1 Queues X X X X X A queue is...

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

View Full Document Right Arrow Icon
1 Queue & Stack
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 Queues A queue is a list in which items are added at one end and deleted from the other end. It is like line of people waiting to purchase tickets: New people can join the line at the back of the line. People at the front of the line are dequeued first (and then they leave the line). This is an example of “First in, First out”, FIFO. Adding an item is called “enqueueing” to the queue. Deleting an item is called “serving” from the queue.
Background image of page 2
3 Queue Terminology Enqueue: Add an item to the back of the queue. Also known as: Insert, Push or enqueue. Dequeue: Delete an item from the front of the queue. Also known as: Delete, Pop or dequeue. Retrieve: Return the value of the item at the front of the queue. Front: The first item in the queue. Rear: The last item in the queue.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Using Queues A Queue class should have the following methods: enqueue(item) //Add an item to the rear of the queue dequeue( ) //Delete an item from the front of the queue retrieve( ) //Return value of front item empty() //Return true if queue is empty.
Background image of page 4
5 Queue Applications Any application where a group of items is waiting to use a shared resource will use a queue. For example: A queue of jobs waiting to use a printer (the print queue). A queue of jobs waiting to use the processor (in a multitasking system).
Background image of page 5

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

View Full DocumentRight Arrow Icon
Implementing Queues with Arrays Three ways to implement queues: The physical model. The Linear model.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

QueueStack - Queue&Stack 1 Queues X X X X X A queue is...

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

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