SlideShare une entreprise Scribd logo
1  sur  18
Queues
Muhammad Hammad Waseem
m.hammad.wasim@gmail.com
Introduction to the Queue
• Like a stack, a queue (pronounced "cue") is a data structure that holds
a sequence of elements.
• A queue, however, provides access to its elements in first-in, first-out
(FIFO) order.
• The elements in a queue are processed like customers standing in a
grocery check-out line: the first customer in line is the first one
served.
Example Applications of Queues
• In a multi-user system, a queue is used to hold print jobs submitted
by users , while the printer services those jobs one at a time.
• Communications software also uses queues to hold information
received over networks and dial-up connections. Sometimes
information is transmitted to a system faster than it can be processed,
so it is placed in a queue when it is received.
Static and Dynamic Queues
• Just as stacks are implemented as arrays or linked lists, so are queues.
• Dynamic queues offer the same advantages over static queues that
dynamic stacks offer over static stacks.
Note: We’ll implement Stack and Queues using linked lists after studying Linked List data structures
Queue Operations
• Think of queues as having a front and a rear. This is illustrated in
Figure.
Queue Operations
• The two primary queue operations are
• enqueuing and
• dequeuing.
• To enqueue means to insert an element at te rear of a queue.
• To dequeue means to remove an element from the front of a queue.
Queue Operations
• Suppose we have an empty static integer queue that is capable of
holding a maximum of three values. With that queue we execute the
following enqueue operations.
Enqueue(3);
Enqueue(6);
Enqueue(9);
Queue Operations
• Figure illustrates the state of the queue after
each of the enqueue operations.
Queue Operations
• Now let's see how dequeue operations are
performed.
• Figure illustrates the state of the queue after
each of three consecutive dequeue operations.
• When the last deqeue operation is performed
in the illustration, the queue is empty. An
empty queue can be signified by setting both
front and rear indices to –1.
Contents of IntQueue.h
class IntQueue
{
private:
int *queueArray;
int queueSize;
int front;
int rear;
int numItems;
public:
IntQueue(int);
~IntQueue(void);
void enqueue(int);
void dequeue(int &);
bool isEmpty(void);
bool isFull(void);
void clear(void);
};
Contents of IntQueue.cpp
#include <iostream.h>
#include "IntQueue.h“
// ******Constructor*******
IntQueue::IntQueue(int s)
{
queueArray = new int[s];
queueSize = s;
front = 0;
rear = 0;
numItems = 0;
}
// *******Destructor*******
IntQueue::~IntQueue(void)
{
delete [] queueArray;
}
Contents of IntQueue.cpp
//********************************************
// Function enqueue inserts the value in num *
// at the rear of the queue. *
//********************************************
void IntQueue::enqueue(int num)
{
if (isFull())
cout << "The queue is full.n";
else
{
// Calculate the new rear position
rear = (rear + 1) % queueSize;
// Insert new item
queueArray[rear] = num;
// Update item count
numItems++;
}
}
Contents of IntQueue.cpp
//*********************************************
// Function dequeue removes the value at the *
// front of the queue, and copies t into num. *
//*********************************************
void IntQueue::dequeue(int &num)
{
if (isEmpty())
cout << "The queue is empty.n";
else
{
// Move front
front = (front + 1) % queueSize;
// Retrieve the front item
num = queueArray[front];
// Update item count
numItems--;
}
}
Contents of IntQueue.cpp
//*********************************************
// Function isEmpty returns true if the queue *
// is empty, and false otherwise. *
//*********************************************
bool IntQueue::isEmpty(void)
{
bool status;
if (numItems)
status = false;
else
status = true;
return status;
}
Contents of IntQueue.cpp
//********************************************
// Function isFull returns true if the queue *
// is full, and false otherwise. *
//********************************************
bool IntQueue::isFull(void)
{
bool status;
if (numItems < queueSize)
status = false;
else
status = true;
return status;
}
Contents of IntQueue.cpp
//*******************************************
// Function clear resets the front and rear *
// indices, and sets numItems to 0. *
//*******************************************
void IntQueue::clear(void)
{
front = queueSize - 1;
rear = queueSize - 1;
numItems = 0;
}
Program: 1
// This program demonstrates the IntQeue class
#include <iostream.h>
#include "intqueue.h“
void main(void)
{
IntQueue iQueue(5);
cout << "Enqueuing 5 items...n";
// Enqueue 5 items.
for (int x = 0; x < 5; x++)
iQueue.enqueue(x);
// Attempt to enqueue a 6th item.
cout << "Now attempting to enqueue again...n";
iQueue.enqueue(5);
Program: 1 (continued)
// Deqeue and retrieve all items in the queue
cout << "The values in the queue were:n";
while (!iQueue.isEmpty())
{
int value;
iQueue.dequeue(value);
cout << value << endl;
}
}
Program Output
Enqueuing 5 items...
Now attempting to enqueue again...
The queue is full.
The values in the queue were:
0

Contenu connexe

Tendances

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 

Tendances (20)

Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
stack & queue
stack & queuestack & queue
stack & queue
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Queues
QueuesQueues
Queues
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
Queue
QueueQueue
Queue
 

En vedette (11)

Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
7 stacksqueues
7 stacksqueues7 stacksqueues
7 stacksqueues
 
16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
 
Lec8
Lec8Lec8
Lec8
 
Linked stacks and queues
Linked stacks and queuesLinked stacks and queues
Linked stacks and queues
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
 
Data structures
Data structuresData structures
Data structures
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
Preparation Data Structures 08 queues
Preparation Data Structures 08 queuesPreparation Data Structures 08 queues
Preparation Data Structures 08 queues
 

Similaire à Data Structures - Lecture 6 [queues]

Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
abinathsabi
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 

Similaire à Data Structures - Lecture 6 [queues] (20)

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Queue
QueueQueue
Queue
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Fundamentals of Data Structure and Queues
Fundamentals of Data Structure and QueuesFundamentals of Data Structure and Queues
Fundamentals of Data Structure and Queues
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Data structure.ppt
Data structure.pptData structure.ppt
Data structure.ppt
 
Queues
QueuesQueues
Queues
 
Queue
QueueQueue
Queue
 
Queues
QueuesQueues
Queues
 
basics of queues
basics of queuesbasics of queues
basics of queues
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Data structures
Data structuresData structures
Data structures
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 

Plus de Muhammad Hammad Waseem

Plus de Muhammad Hammad Waseem (20)

[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
[ITP - Lecture 14] Recursion
[ITP - Lecture 14] Recursion[ITP - Lecture 14] Recursion
[ITP - Lecture 14] Recursion
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
 
[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)
 
[ITP - Lecture 07] Comments in C/C++
[ITP - Lecture 07] Comments in C/C++[ITP - Lecture 07] Comments in C/C++
[ITP - Lecture 07] Comments in C/C++
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++
 
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 

Dernier

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

Data Structures - Lecture 6 [queues]

  • 2. Introduction to the Queue • Like a stack, a queue (pronounced "cue") is a data structure that holds a sequence of elements. • A queue, however, provides access to its elements in first-in, first-out (FIFO) order. • The elements in a queue are processed like customers standing in a grocery check-out line: the first customer in line is the first one served.
  • 3. Example Applications of Queues • In a multi-user system, a queue is used to hold print jobs submitted by users , while the printer services those jobs one at a time. • Communications software also uses queues to hold information received over networks and dial-up connections. Sometimes information is transmitted to a system faster than it can be processed, so it is placed in a queue when it is received.
  • 4. Static and Dynamic Queues • Just as stacks are implemented as arrays or linked lists, so are queues. • Dynamic queues offer the same advantages over static queues that dynamic stacks offer over static stacks. Note: We’ll implement Stack and Queues using linked lists after studying Linked List data structures
  • 5. Queue Operations • Think of queues as having a front and a rear. This is illustrated in Figure.
  • 6. Queue Operations • The two primary queue operations are • enqueuing and • dequeuing. • To enqueue means to insert an element at te rear of a queue. • To dequeue means to remove an element from the front of a queue.
  • 7. Queue Operations • Suppose we have an empty static integer queue that is capable of holding a maximum of three values. With that queue we execute the following enqueue operations. Enqueue(3); Enqueue(6); Enqueue(9);
  • 8. Queue Operations • Figure illustrates the state of the queue after each of the enqueue operations.
  • 9. Queue Operations • Now let's see how dequeue operations are performed. • Figure illustrates the state of the queue after each of three consecutive dequeue operations. • When the last deqeue operation is performed in the illustration, the queue is empty. An empty queue can be signified by setting both front and rear indices to –1.
  • 10. Contents of IntQueue.h class IntQueue { private: int *queueArray; int queueSize; int front; int rear; int numItems; public: IntQueue(int); ~IntQueue(void); void enqueue(int); void dequeue(int &); bool isEmpty(void); bool isFull(void); void clear(void); };
  • 11. Contents of IntQueue.cpp #include <iostream.h> #include "IntQueue.h“ // ******Constructor******* IntQueue::IntQueue(int s) { queueArray = new int[s]; queueSize = s; front = 0; rear = 0; numItems = 0; } // *******Destructor******* IntQueue::~IntQueue(void) { delete [] queueArray; }
  • 12. Contents of IntQueue.cpp //******************************************** // Function enqueue inserts the value in num * // at the rear of the queue. * //******************************************** void IntQueue::enqueue(int num) { if (isFull()) cout << "The queue is full.n"; else { // Calculate the new rear position rear = (rear + 1) % queueSize; // Insert new item queueArray[rear] = num; // Update item count numItems++; } }
  • 13. Contents of IntQueue.cpp //********************************************* // Function dequeue removes the value at the * // front of the queue, and copies t into num. * //********************************************* void IntQueue::dequeue(int &num) { if (isEmpty()) cout << "The queue is empty.n"; else { // Move front front = (front + 1) % queueSize; // Retrieve the front item num = queueArray[front]; // Update item count numItems--; } }
  • 14. Contents of IntQueue.cpp //********************************************* // Function isEmpty returns true if the queue * // is empty, and false otherwise. * //********************************************* bool IntQueue::isEmpty(void) { bool status; if (numItems) status = false; else status = true; return status; }
  • 15. Contents of IntQueue.cpp //******************************************** // Function isFull returns true if the queue * // is full, and false otherwise. * //******************************************** bool IntQueue::isFull(void) { bool status; if (numItems < queueSize) status = false; else status = true; return status; }
  • 16. Contents of IntQueue.cpp //******************************************* // Function clear resets the front and rear * // indices, and sets numItems to 0. * //******************************************* void IntQueue::clear(void) { front = queueSize - 1; rear = queueSize - 1; numItems = 0; }
  • 17. Program: 1 // This program demonstrates the IntQeue class #include <iostream.h> #include "intqueue.h“ void main(void) { IntQueue iQueue(5); cout << "Enqueuing 5 items...n"; // Enqueue 5 items. for (int x = 0; x < 5; x++) iQueue.enqueue(x); // Attempt to enqueue a 6th item. cout << "Now attempting to enqueue again...n"; iQueue.enqueue(5);
  • 18. Program: 1 (continued) // Deqeue and retrieve all items in the queue cout << "The values in the queue were:n"; while (!iQueue.isEmpty()) { int value; iQueue.dequeue(value); cout << value << endl; } } Program Output Enqueuing 5 items... Now attempting to enqueue again... The queue is full. The values in the queue were: 0