SlideShare a Scribd company logo
Queue
Queue Overview
• Queue ADT
• Basic operations of queue
– Push (or Enqueue), Pop (or Dequeue) etc.
• Implementations of queue using
– array
– linked list
Queue
• How to include a new person/item?
• How to remove a particular person/item?
Queue
• Collection of items into which items
may be added from rear end and
from which items may be removed
from the front end
The Queue ADT
• Fundamental operations:
– Enqueue: Equivalent to an insert
– Dequeue: Deletes the element from rear end
– isEmpty: Returns true if there are no elements in the queue
– ReadFront: Examines the element at the front of the queue
– ReadRear: Examines the elements at the rear of the queue
Enqueue and Dequeue
Queue ADT Specification
Structure: Elements are added to one end and removed from the other end.
Definitions: (Provided by user):
MAX_ITEMS: Maximum number of items that might be on the queue.
Item Type: Data type of the items on the queue.
Operations: (Provided by the ADT):
MakeEmpty
Functions: Sets queue to an empty state.
Preconditions: None
PostCondition: Queue is empty.
Boolean IsEmpty
Functions: Determine whether the queue is empty.
Preconditions: Queue has been initialized.
PostCondition: Function value = (queue is empty)
Boolean IsFull
Functions: Determine whether the queue is full.
Preconditions: Queue has been initialized.
PostCondition: Function value = (queue is full)
Enqueue (ItemType newItem)
Functions: Add newItem at the rear of the queue.
Preconditions: Queue has been initialized and is not full.
PostCondition: newItem at the rear of the queue.
Dequeue (ItemType& item)
Functions: Remove tem from front of queue and returns it in item.
Preconditions: Queue has been initialized and is not empty.
PostCondition: The element at front has been removed from the queue.
Item is copy of removed element.
Queue ADT
• Queue is known as FIFO (First In, First Out) lists.
– The last element inserted will be the last to be retrieved
Implementation of Queue
• Any list implementation could be used to implement a queue
– Arrays (static: the size of queue is given initially)
– Linked lists (dynamic: never become full, except when memory
overflows)
• We will explore implementations based on array and linked list
• Let’s see how to use an array to implement a queue first
Array Implementation
• Need to declare an array size ahead of time
• Associated with each queue are front and rear
– for an empty queue, set front and rear to -1
• enqueue (X)
– (1) Increment front by 1 if front = -1
– (2) Increment rear by 1
– (3) Set queue[rear] = X
• dequeue
– (1) Delete value to queue[front]
– (2) Increment front by 1
• These operations are performed in constant time?
Queue class
• Attributes of Queue
– capacity: the max size of queue
– rear: the index of the last element of queue
– front: the index of the first element of queue
– values: point to an array which stores elements of queue
• Operations of Queue
– IsEmpty: return true if queue is empty, return false
otherwise
– isFull: return true if queue is full, return false otherwise
– readFront: return the element at the front of queue
– readRear: return the element at the rear of queue
– enqueue: add an element to the rear of queue
– dequeue: delete the element from the front of queue
– displayQueue: print all the data in the queue
Implementing a Queue Class
• Define data members: consider storage structure(s)
• Attempt #1: Use an array with the rear and front equal to -1
e.g., Enqueue 75, Enqueue 89, Enqueue 64, …
front rear
75 89 64
[0] [1] [2] [3] [4]
• … Dequeue
front rear
89 64
[0] [1] [2] [3] [4]
front rear
89 64
[0] [1] [2] [3] [4]
Dequeue
(1) Delete queue[front]
(2) Increment front by 1
Problem?
front rear
89 64
[0] [1] [2] [3] [4]
OR
front rear
89 64
[0] [1] [2] [3] [4]
Dequeue ??????
(1) Delete value of queue[front]
(2) Increment front by 1?????
Queue class
class Queue {
public:
Queue(int size = 10); // constructor
~Queue() { delete [] values; } // destructor
bool isEmpty() { return rear == -1; }
bool isFull() { return (rear-front) == maxRear; }
double readFront();
double readRear();
void enqueue(double x);
void dequeue();
void displayQueue();
private:
int maxRear; // maxRear = capacity - 1
int rear; // index of currently inserted value
int front; // index of next element to be deleted
double [] values; // element array
};
Create Queue
• The constructor of Queue
– Allocate an array of size. By default,
size = 10.
– When the queue is full, rear will have its maximum
value, i.e. capacity – 1.
– Initially rear is set to -1. It means the queue is empty.
Queue::Queue(int capacity /*= 10*/) {
if(capacity<1) {
cout<<“cannot create queue of size below 1”;
return;
}
maxRear= capacity - 1;
values = new double[capacity];
front = rear = -1;
}
Although the constructor
dynamically allocates the queue
array, the queue is still static. The
size is fixed after the initialization.
Enqueue
• void Enqueue(double x);
– Add an element to the queue
– If the queue is full, print the error information.
– Note rear always represents the index of the
recently added element. Before adding an element,
increment rear.
void Queue::enqueue(const double x) {
if (IsFull())
cout << "Error: the queue is full." << endl;
else
values[++rear] = x; //is it correct?
}
Dequeue
• double dequeue()
– Removes and return the element at the front of the queue
– If the queue is empty, print the error information. (In this
case, the return value is useless.)
– Don’t forgot to shift all elements to left and modify rear
void Queue::dequeue() {
if (IsEmpty()) {
cout << "Error: the queue is empty." << endl;
return;
}
else {
shiftElementsLeft();
//rear???
}
}
Queue Rear
• double readRear()
– Return the element at rear of the queue
– Unlike dequeue, this function does not remove
the element
double Queue::readRear() {
if (IsEmpty()) {
cout << "Error: the queue is empty." << endl;
return -1;
}
else
return values[rear];
}
Queue Front
• double readFront()
– Return the element at front of the queue
– Unlike dequeue, this function does not remove
the element
double Queue::readFront() {
if (IsEmpty()) {
cout << "Error: the queue is empty." << endl;
return -1;
}
else
return values[front];
}
Using Queue
int main(void) {
Queue q(5);
q.enqueue(5.0);
q.enqueue(6.5);
q.enqueue(-3.0);
q.enqueue(-8.0);
q.displayQueue();
cout << “Front: " << q.getFront() << endl;
cout << “Rear: " << q.getRear() << endl;
q.dequeue();
cout << “Rear: " << q.getRear() << endl;
cout << “Front: " << q.getFront() << endl;
while (!q.isEmpty()) q.dequeue();
q.displayQueue();
return 0;
}
Result????
Circular Queue
Circular Queue
• enqueue(X)?
• dequeue()?
• isEmpty()?
• isFull()?
• Constructor?
• readFront()?
• readRear()?
Circular Queue
• Enqueue(X)?rear = (rear+1)%capacity; values[rear]=x;
• Dequeue()?if (!isEmpty()){front = (front+1)%capacity; return
values[front]}
• isEmpty()? return front == rear;
• isFull()? return ((rear+1)%capacity) == front;
• Constructor? set front = rear = 0
• readFront()?  if (!isEmpty()){return values[(front+1)%capacity];}
• readRear()?  if (!isEmpty()){return values[rear];}
Circular Queue
• Alternate implementation?
• Any modification in Queue class?
– elementCount or currentSize??
References
• Data Structures and Algorithms, LUMS

More Related Content

PPTX
Queue - Data Structure - Notes
Omprakash Chauhan
 
PPTX
EER modeling
Dabbal Singh Mahara
 
PPTX
Deque and its applications
Jsaddam Hussain
 
PPTX
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
PPTX
Presentation on queue
Rojan Pariyar
 
PPT
Recursion - Algorithms and Data Structures
Priyanka Rana
 
PPTX
single linked list
Sathasivam Rangasamy
 
Queue - Data Structure - Notes
Omprakash Chauhan
 
EER modeling
Dabbal Singh Mahara
 
Deque and its applications
Jsaddam Hussain
 
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
Presentation on queue
Rojan Pariyar
 
Recursion - Algorithms and Data Structures
Priyanka Rana
 
single linked list
Sathasivam Rangasamy
 

What's hot (20)

PPT
SQL subquery
Vikas Gupta
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPTX
Bfs and Dfs
Masud Parvaze
 
PPT
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPTX
queue & its applications
somendra kumar
 
PDF
DS UNIT 1.pdf
SeethaDinesh
 
PPTX
Knapsack problem dynamicprogramming
rowntu
 
PPTX
Divide and Conquer
Melaku Bayih Demessie
 
PDF
STL in C++
Surya Prakash Sahu
 
PPTX
Unit 4 queue
Dabbal Singh Mahara
 
PPT
Breadth first search and depth first search
Hossain Md Shakhawat
 
PPTX
6-Python-Recursion PPT.pptx
Venkateswara Babu Ravipati
 
PPTX
Skip lists (Advance Data structure)
Shubham Shukla
 
PPTX
Queue
Raj Sarode
 
PPT
Binary search tree(bst)
Hossain Md Shakhawat
 
PPTX
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
PPT
Array in Java
Shehrevar Davierwala
 
PDF
Mapping ER and EER Model
Mary Brinda
 
PPTX
Doubly Linked List
V.V.Vanniaperumal College for Women
 
SQL subquery
Vikas Gupta
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Bfs and Dfs
Masud Parvaze
 
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
queue & its applications
somendra kumar
 
DS UNIT 1.pdf
SeethaDinesh
 
Knapsack problem dynamicprogramming
rowntu
 
Divide and Conquer
Melaku Bayih Demessie
 
STL in C++
Surya Prakash Sahu
 
Unit 4 queue
Dabbal Singh Mahara
 
Breadth first search and depth first search
Hossain Md Shakhawat
 
6-Python-Recursion PPT.pptx
Venkateswara Babu Ravipati
 
Skip lists (Advance Data structure)
Shubham Shukla
 
Queue
Raj Sarode
 
Binary search tree(bst)
Hossain Md Shakhawat
 
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Array in Java
Shehrevar Davierwala
 
Mapping ER and EER Model
Mary Brinda
 
Ad

Similar to Queue (20)

PPTX
Queues_0748555555555555555555555526.pptx
nailapp2023
 
PPT
Lec-07 Queues.ppt queues introduction to queue
AmsaAzeem
 
PPT
Lecture 2d queues
Victor Palmar
 
PDF
Queue ADT for data structure for computer
abinathsabi
 
PPTX
Queue and its operations
V.V.Vanniaperumal College for Women
 
PPTX
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
PPSX
Queue by rajanikanth
btechsmartclass
 
PPTX
Queue
Abdur Rehman
 
PPT
Algo>Queues
Ain-ul-Moiz Khawaja
 
PDF
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
playstore9ha
 
PDF
Polynomialmotilalanehrunationalinstitute.pdf
yugpadhiyar2006
 
PPTX
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
PPTX
The presention is about the queue data structure
gaurav77712
 
PPTX
Queues
nidhisatija1
 
PPT
Queue data structure
Mekk Mhmd
 
PPTX
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
PPT
Queues in C++ detailed explanation and examples .ppt
Jamiluddin39
 
PPTX
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
PPTX
Queues in C++
Vineeta Garg
 
PPTX
queue.pptx
Dr.Shweta
 
Queues_0748555555555555555555555526.pptx
nailapp2023
 
Lec-07 Queues.ppt queues introduction to queue
AmsaAzeem
 
Lecture 2d queues
Victor Palmar
 
Queue ADT for data structure for computer
abinathsabi
 
Queue and its operations
V.V.Vanniaperumal College for Women
 
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
Queue by rajanikanth
btechsmartclass
 
Algo>Queues
Ain-ul-Moiz Khawaja
 
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
playstore9ha
 
Polynomialmotilalanehrunationalinstitute.pdf
yugpadhiyar2006
 
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
The presention is about the queue data structure
gaurav77712
 
Queues
nidhisatija1
 
Queue data structure
Mekk Mhmd
 
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Queues in C++ detailed explanation and examples .ppt
Jamiluddin39
 
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Queues in C++
Vineeta Garg
 
queue.pptx
Dr.Shweta
 
Ad

More from Ayaz Akhtar (12)

PPTX
Boiler presentation
Ayaz Akhtar
 
PPTX
Conjunctivitis
Ayaz Akhtar
 
PPTX
Common cold
Ayaz Akhtar
 
PPTX
Diabetes clinical
Ayaz Akhtar
 
PDF
Trw presentation,
Ayaz Akhtar
 
PPTX
Malaria
Ayaz Akhtar
 
PPTX
Drug laws
Ayaz Akhtar
 
PPTX
Meningitis
Ayaz Akhtar
 
PPTX
Rabies
Ayaz Akhtar
 
PPTX
managers and management
Ayaz Akhtar
 
PPTX
Concept nature and principles of management
Ayaz Akhtar
 
PPTX
Continuous casting of billets
Ayaz Akhtar
 
Boiler presentation
Ayaz Akhtar
 
Conjunctivitis
Ayaz Akhtar
 
Common cold
Ayaz Akhtar
 
Diabetes clinical
Ayaz Akhtar
 
Trw presentation,
Ayaz Akhtar
 
Malaria
Ayaz Akhtar
 
Drug laws
Ayaz Akhtar
 
Meningitis
Ayaz Akhtar
 
Rabies
Ayaz Akhtar
 
managers and management
Ayaz Akhtar
 
Concept nature and principles of management
Ayaz Akhtar
 
Continuous casting of billets
Ayaz Akhtar
 

Recently uploaded (20)

PPT
IHRM(international human resource management) PPT NEW.ppt
Sunaina44
 
PDF
Asia’s Healthcare Power Players - The Visionary CEOs Reshaping Medicine for 4...
Gorman Bain Capital
 
PPTX
Cynthia Kayle Share 5 Ways Parents Can Protect Their Children From Trafficker...
Cynthia Kayle
 
PDF
250621-Medical Review in Pharmacovigilance-CQS.pdf
Obaid Ali / Roohi B. Obaid
 
PDF
Intro to Org Topologies by Rowan Bunning.pdf
Rowan Bunning
 
PPTX
Letter of credit which matters to Import and Export policy
atifaslam1482
 
PPTX
Introduction to product management –Module 1.pptx
FarheenAhmad9
 
PPTX
Multicolor leadership kepemimpinan untuk organisasi
GusTri5
 
PPTX
Leadership Meaning and Styles- Autocratic, Paternalis--
PoojaShetty805509
 
PDF
2024_10 Approach to selecting a CPM Application
tanbir16
 
PDF
OBSTRUCTIONS OF TURKISH PUBLIC ORGANIZATIONS GETTING ISO/IEC 27001 CERTIFIED
ijmvsc
 
PDF
Biography Of Carl Alameda | Assistant City Manager
Carl Alameda
 
PDF
Branding Potentials of Keyword Search Ads The Effects of Ad Rankings on Bran...
hritikamishra2k
 
PDF
250712-Role Plays for Hands on Exercise-CQS.pdf
Obaid Ali / Roohi B. Obaid
 
PPTX
Agile Chennai 18-19 July 2025 | Leading with Integrity in the Age of AI – A C...
AgileNetwork
 
PPTX
Using the DISC for Leadership Development.pptx
joetrojan
 
PDF
Dynamic Capabilities for a Sustainable Future
David Teece
 
PPTX
Project Management with Knowledge Areas and AI
Usman Zafar Malik
 
PDF
confessions of a CMO_sxsw_panel picker.pdf
GabrielCohen28
 
PDF
250719-Individual Case Safety Reports-CQS.pdf
Obaid Ali / Roohi B. Obaid
 
IHRM(international human resource management) PPT NEW.ppt
Sunaina44
 
Asia’s Healthcare Power Players - The Visionary CEOs Reshaping Medicine for 4...
Gorman Bain Capital
 
Cynthia Kayle Share 5 Ways Parents Can Protect Their Children From Trafficker...
Cynthia Kayle
 
250621-Medical Review in Pharmacovigilance-CQS.pdf
Obaid Ali / Roohi B. Obaid
 
Intro to Org Topologies by Rowan Bunning.pdf
Rowan Bunning
 
Letter of credit which matters to Import and Export policy
atifaslam1482
 
Introduction to product management –Module 1.pptx
FarheenAhmad9
 
Multicolor leadership kepemimpinan untuk organisasi
GusTri5
 
Leadership Meaning and Styles- Autocratic, Paternalis--
PoojaShetty805509
 
2024_10 Approach to selecting a CPM Application
tanbir16
 
OBSTRUCTIONS OF TURKISH PUBLIC ORGANIZATIONS GETTING ISO/IEC 27001 CERTIFIED
ijmvsc
 
Biography Of Carl Alameda | Assistant City Manager
Carl Alameda
 
Branding Potentials of Keyword Search Ads The Effects of Ad Rankings on Bran...
hritikamishra2k
 
250712-Role Plays for Hands on Exercise-CQS.pdf
Obaid Ali / Roohi B. Obaid
 
Agile Chennai 18-19 July 2025 | Leading with Integrity in the Age of AI – A C...
AgileNetwork
 
Using the DISC for Leadership Development.pptx
joetrojan
 
Dynamic Capabilities for a Sustainable Future
David Teece
 
Project Management with Knowledge Areas and AI
Usman Zafar Malik
 
confessions of a CMO_sxsw_panel picker.pdf
GabrielCohen28
 
250719-Individual Case Safety Reports-CQS.pdf
Obaid Ali / Roohi B. Obaid
 

Queue

  • 2. Queue Overview • Queue ADT • Basic operations of queue – Push (or Enqueue), Pop (or Dequeue) etc. • Implementations of queue using – array – linked list
  • 3. Queue • How to include a new person/item? • How to remove a particular person/item?
  • 4. Queue • Collection of items into which items may be added from rear end and from which items may be removed from the front end
  • 5. The Queue ADT • Fundamental operations: – Enqueue: Equivalent to an insert – Dequeue: Deletes the element from rear end – isEmpty: Returns true if there are no elements in the queue – ReadFront: Examines the element at the front of the queue – ReadRear: Examines the elements at the rear of the queue
  • 7. Queue ADT Specification Structure: Elements are added to one end and removed from the other end. Definitions: (Provided by user): MAX_ITEMS: Maximum number of items that might be on the queue. Item Type: Data type of the items on the queue. Operations: (Provided by the ADT): MakeEmpty Functions: Sets queue to an empty state. Preconditions: None PostCondition: Queue is empty. Boolean IsEmpty Functions: Determine whether the queue is empty. Preconditions: Queue has been initialized. PostCondition: Function value = (queue is empty) Boolean IsFull Functions: Determine whether the queue is full. Preconditions: Queue has been initialized. PostCondition: Function value = (queue is full) Enqueue (ItemType newItem) Functions: Add newItem at the rear of the queue. Preconditions: Queue has been initialized and is not full. PostCondition: newItem at the rear of the queue. Dequeue (ItemType& item) Functions: Remove tem from front of queue and returns it in item. Preconditions: Queue has been initialized and is not empty. PostCondition: The element at front has been removed from the queue. Item is copy of removed element.
  • 8. Queue ADT • Queue is known as FIFO (First In, First Out) lists. – The last element inserted will be the last to be retrieved
  • 9. Implementation of Queue • Any list implementation could be used to implement a queue – Arrays (static: the size of queue is given initially) – Linked lists (dynamic: never become full, except when memory overflows) • We will explore implementations based on array and linked list • Let’s see how to use an array to implement a queue first
  • 10. Array Implementation • Need to declare an array size ahead of time • Associated with each queue are front and rear – for an empty queue, set front and rear to -1 • enqueue (X) – (1) Increment front by 1 if front = -1 – (2) Increment rear by 1 – (3) Set queue[rear] = X • dequeue – (1) Delete value to queue[front] – (2) Increment front by 1 • These operations are performed in constant time?
  • 11. Queue class • Attributes of Queue – capacity: the max size of queue – rear: the index of the last element of queue – front: the index of the first element of queue – values: point to an array which stores elements of queue • Operations of Queue – IsEmpty: return true if queue is empty, return false otherwise – isFull: return true if queue is full, return false otherwise – readFront: return the element at the front of queue – readRear: return the element at the rear of queue – enqueue: add an element to the rear of queue – dequeue: delete the element from the front of queue – displayQueue: print all the data in the queue
  • 12. Implementing a Queue Class • Define data members: consider storage structure(s) • Attempt #1: Use an array with the rear and front equal to -1 e.g., Enqueue 75, Enqueue 89, Enqueue 64, … front rear 75 89 64 [0] [1] [2] [3] [4] • … Dequeue front rear 89 64 [0] [1] [2] [3] [4] front rear 89 64 [0] [1] [2] [3] [4] Dequeue (1) Delete queue[front] (2) Increment front by 1
  • 13. Problem? front rear 89 64 [0] [1] [2] [3] [4] OR front rear 89 64 [0] [1] [2] [3] [4] Dequeue ?????? (1) Delete value of queue[front] (2) Increment front by 1?????
  • 14. Queue class class Queue { public: Queue(int size = 10); // constructor ~Queue() { delete [] values; } // destructor bool isEmpty() { return rear == -1; } bool isFull() { return (rear-front) == maxRear; } double readFront(); double readRear(); void enqueue(double x); void dequeue(); void displayQueue(); private: int maxRear; // maxRear = capacity - 1 int rear; // index of currently inserted value int front; // index of next element to be deleted double [] values; // element array };
  • 15. Create Queue • The constructor of Queue – Allocate an array of size. By default, size = 10. – When the queue is full, rear will have its maximum value, i.e. capacity – 1. – Initially rear is set to -1. It means the queue is empty. Queue::Queue(int capacity /*= 10*/) { if(capacity<1) { cout<<“cannot create queue of size below 1”; return; } maxRear= capacity - 1; values = new double[capacity]; front = rear = -1; } Although the constructor dynamically allocates the queue array, the queue is still static. The size is fixed after the initialization.
  • 16. Enqueue • void Enqueue(double x); – Add an element to the queue – If the queue is full, print the error information. – Note rear always represents the index of the recently added element. Before adding an element, increment rear. void Queue::enqueue(const double x) { if (IsFull()) cout << "Error: the queue is full." << endl; else values[++rear] = x; //is it correct? }
  • 17. Dequeue • double dequeue() – Removes and return the element at the front of the queue – If the queue is empty, print the error information. (In this case, the return value is useless.) – Don’t forgot to shift all elements to left and modify rear void Queue::dequeue() { if (IsEmpty()) { cout << "Error: the queue is empty." << endl; return; } else { shiftElementsLeft(); //rear??? } }
  • 18. Queue Rear • double readRear() – Return the element at rear of the queue – Unlike dequeue, this function does not remove the element double Queue::readRear() { if (IsEmpty()) { cout << "Error: the queue is empty." << endl; return -1; } else return values[rear]; }
  • 19. Queue Front • double readFront() – Return the element at front of the queue – Unlike dequeue, this function does not remove the element double Queue::readFront() { if (IsEmpty()) { cout << "Error: the queue is empty." << endl; return -1; } else return values[front]; }
  • 20. Using Queue int main(void) { Queue q(5); q.enqueue(5.0); q.enqueue(6.5); q.enqueue(-3.0); q.enqueue(-8.0); q.displayQueue(); cout << “Front: " << q.getFront() << endl; cout << “Rear: " << q.getRear() << endl; q.dequeue(); cout << “Rear: " << q.getRear() << endl; cout << “Front: " << q.getFront() << endl; while (!q.isEmpty()) q.dequeue(); q.displayQueue(); return 0; } Result????
  • 22. Circular Queue • enqueue(X)? • dequeue()? • isEmpty()? • isFull()? • Constructor? • readFront()? • readRear()?
  • 23. Circular Queue • Enqueue(X)?rear = (rear+1)%capacity; values[rear]=x; • Dequeue()?if (!isEmpty()){front = (front+1)%capacity; return values[front]} • isEmpty()? return front == rear; • isFull()? return ((rear+1)%capacity) == front; • Constructor? set front = rear = 0 • readFront()?  if (!isEmpty()){return values[(front+1)%capacity];} • readRear()?  if (!isEmpty()){return values[rear];}
  • 24. Circular Queue • Alternate implementation? • Any modification in Queue class? – elementCount or currentSize??
  • 25. References • Data Structures and Algorithms, LUMS