Queues and its application, Study notes of Data Structures and Algorithms

This is about Queuein easy way

Typology: Study notes

2018/2019

Uploaded on 11/22/2019

muhammad-farooq-8
muhammad-farooq-8 🇵🇰

11 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Structures and Algorithms
LECTURE 09 QUEUES
FALL 2019 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Queues and its application and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Data Structures and Algorithms

LECTURE 09 – QUEUES

Queue

  • A queue is a “waiting line”, that grows by adding elements to its end and shrinks by

taking elements from its front

  • Unlike stack, a queue is a structure in which both ends are used:
    • One for adding new elements
    • And one for removing elements
  • Last element has to wait until all the elements preceding it are removed
  • Queue is a FIFO : First In, First Out, structure

Queue Operations

  • Enqueue
    • Adding items at the back of queue
  • Dequeue
    • Removing items from the front

Queue Operations clear() // clear the queue isEmpty() // check to see if the queue is empty isFull() // check to see if the queue is full enqueue(el) // Add element el at the back of queue dequeue() // remove the first element from the //front firstEl() // return the value of the first element in the // queue without removing it

Queue Implementation

  • The queue is empty when
    • First == −
  • The queue is full when
    • First == 0 && Last == size- 1
    • OR
    • First == Last +1 (we will see this condition next)

Queue Operations

  • Enqueue(66)
  • Enqueue(8)
  • Enqueue(12)
  • Queue is now full

Queue Operations

  • Dequeue()
  • Two options
    1. Remove the first element and then increment the First index – Circular Queue

Circular Queue

Circular Queue

  • Dequeue()

Array Queue Implementation

  • Please see the hand out - Queue