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

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

View Full Document Right Arrow Icon
1 Queue & Stack
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 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.
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.
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 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.
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).
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern