Queues - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Queues

Description:

Like the stack, access to the elements in the queue is restricted. ... LIFO manner, the queue retrieves elements in A FIFO (first in, first out) manner. ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 10
Provided by: cseBu
Category:
Tags: manner | queues

less

Transcript and Presenter's Notes

Title: Queues


1
Queues
2
What is a Queue?
  • A queue is an ordered data structure similar to
    the list and the stack.
  • Like the stack, access to the elements in the
    queue is restricted.
  • Unlike the stack, which retrieved elements in a
    LIFO manner, the queue retrieves elements in A
    FIFO (first in, first out) manner.

3
Real Life Examples
  • People waiting in line
  • Your call will be handled in the order that it
    was received
  • Threads in an application

4
Queue Operations
  • Enqueue add an element to the end of the queue
  • Dequeue remove the element from the front of
    the queue
  • getFront look at the element in the front of
    the queue
  • isEmpty is the queue empty or not
  • Clear remove all elements from the queue

5
Variant Types
  • There are some variants of queues to handle
    common additional requirements. For example, a
    queue can model a line. But, if you get to the
    head of the line, and you forgot to fill out a
    form, they might ask you to step to the side,
    fill it out, then get back in the head of the
    line. Also, people in the back of the line might
    get tired of waiting and leave.

6
Deque
  • The Deque (or Double Ended Queue) allows addition
    and removal from both ends of the queue.
  • See Deque.java

7
Variant Types
  • A queue could be used to model a line of people
    waiting to board an airplane. But, in this line,
    first class customers get to go first, and then
    business class customers, and then coach. But
    within their respective classes, its first come,
    first served. This is a Priority Queue.

8
Priority Queue
  • The interface for the priority queue is exactly
    the same as for the regular queue, with the
    exception that rather than taking objects of any
    type, the priority queue will only take objects
    that can be compared to each other, and ranked in
    order of priority. Dequeue will always return
    the highest priority elements first.
  • See PriorityQueue.java

9
Questions
  • Which underlying data structure do you think
    would be best for implementing a queue? A deque?
    A priority queue?
Write a Comment
User Comments (0)
About PowerShow.com