SlideShare a Scribd company logo
A class for Dynamic Queue implementation
class DynIntQueue
{
private:
struct QueueNode
{
int value;
QueueNode *next;
};
QueueNode *front;
QueueNode *rear;
int numItems;
public:
DynIntQueue(void);
~DynIntQueue(void);
void enqueue(int);
int dequeue(void);
bool isEmpty(void);
void makeNull(void);
};
Implemenaton
//************************
// Constructor *
//************************
DynIntQueue::DynIntQueue(void)
{
front = NULL;
rear = NULL;
numItems = 0;
}
//************************
// Destructor *
//************************
DynIntQueue::~DynIntQueue(void)
{
makeNull();
}
//********************************************
// Function enqueue inserts the value in num *
// at the rear of the queue. *
//********************************************
void DynIntQueue::enqueue(int num)
{
QueueNode *newNode;
newNode = new QueueNode;
newNode->value = num;
newNode->next = NULL;
if (isEmpty())
{
front = newNode;
rear = newNode;
}
else
{
rear->next = newNode;
rear = newNode;
}
numItems++;
}
//**********************************************
// Function dequeue removes the value at the *
// front of the queue, and copies it into num. *
//**********************************************
int DynIntQueue::dequeue(void)
{
QueueNode *temp;
int num;
if (isEmpty())
cout << "The queue is empty.n";
else
{
num = front->value;
temp = front->next;
delete front;
front = temp;
numItems--;
}
return num;
}
//*********************************************
// Function isEmpty returns true if the queue *
// is empty, and false otherwise. *
//*********************************************
bool DynIntQueue::isEmpty(void)
{
if (numItems)
return false;
else
return true;
}
//********************************************
// Function makeNull dequeues all the elements *
// in the queue. *
//********************************************
void DynIntQueue::makeNull(void)
{
while(!isEmpty())
dequeue();
}
Program
// This program demonstrates the DynIntQeue class
void main(void)
{
DynIntQueue iQueue;
cout << "Enqueuing 5 items...n";
// Enqueue 5 items.
for (int x = 0; x < 5; x++)
iQueue.enqueue(x);
// Deqeue and retrieve all items in the queue
cout << "The values in the queue were:n";
while (!iQueue.isEmpty())
{
int value;
value =iQueue.dequeue();
cout << value << endl;
}
}
Program Ouput
Enqueuing 5 items...
The values in the queue were:
0
1
2
3
4

More Related Content

PDF
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
PPT
Algo>Queues
PPT
Function enqueue inserts the value in num
PPT
Lec-12, 13 Quees In Queue IntQueue(int s)
PPT
Lec-12, 13 Queues - IntQueue IntQueue(int s) //constructor
PDF
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
PDF
in this assignment you are asked to write a simple driver program an.pdf
PDF
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
Algo>Queues
Function enqueue inserts the value in num
Lec-12, 13 Quees In Queue IntQueue(int s)
Lec-12, 13 Queues - IntQueue IntQueue(int s) //constructor
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
in this assignment you are asked to write a simple driver program an.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf

Similar to Lec-12, 13 Quees A class for Dynamic Queue implementation (20)

PPT
Class ‘increment’
PDF
Please read the comment ins codeExpressionTree.java-------------.pdf
PDF
#includeiostream#includecstdio#includecstdlib Node .pdf
PDF
#includeiostream#includecstdio#includecstdlibusing names.pdf
PDF
Print Star pattern in java and print triangle of stars in java
PDF
C++ Program to Implement Doubly Linked List #includei.pdf
PDF
(In java language)1. Use recursion in implementing the binarySearc.pdf
PDF
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
ODP
Writing MySQL UDFs
PDF
Need Help with this Java Assignment. Program should be done in JAVA .pdf
PPTX
Treatment, Architecture and Threads
PDF
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
DOCX
DOCX
C# labprograms
DOCX
Codigo fuente
PDF
mainpublic class AssignmentThree {    public static void ma.pdf
PDF
Objective Min-heap queue with customized comparatorHospital emerg.pdf
PPTX
DesignPatterns-IntroPresentation.pptx
PDF
#include &lt;stdio.h&gt; #include &lt;malloc.h&gt; #define ISEMP.pdf
PDF
Tested on EclipseBoth class should be in same package.pdf
Class ‘increment’
Please read the comment ins codeExpressionTree.java-------------.pdf
#includeiostream#includecstdio#includecstdlib Node .pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
Print Star pattern in java and print triangle of stars in java
C++ Program to Implement Doubly Linked List #includei.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
Writing MySQL UDFs
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Treatment, Architecture and Threads
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
C# labprograms
Codigo fuente
mainpublic class AssignmentThree {    public static void ma.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdf
DesignPatterns-IntroPresentation.pptx
#include &lt;stdio.h&gt; #include &lt;malloc.h&gt; #define ISEMP.pdf
Tested on EclipseBoth class should be in same package.pdf
Ad

More from Anil Yadav (20)

PPTX
Link List : Introduction to List and Linked Lists
PPTX
Link List REPRESENTATION OF DOUBLY LINKED LIST
PPTX
ALGORITHM FOR PUSHING AN ELEMENT TO A QUEUE
PPTX
Link List STACK and Queue USING LINKED LIST
PPTX
Link List Programming Linked List in Cpp
PPTX
Link List & ALGORITHM FOR DELETING A NODE
PPTX
Link List ALGORITHM FOR INSERTING A NODE
PPTX
Presentations Linked Lists Data Structure
PPT
Lec-12, 13 Quees First In First Out (FIFO)
PPT
Lec-12, 13 Quee s Applications of Queues
PPT
Lec-12, 13 Quees Array Implementation IN
PPT
Lec-12, 13 Quees -How to determine empty and full Queues?
PDF
Unit2-BIS Business Information system Data
PPT
Lec-12, 13 Quees Another implementation of Queues using Arrays
PPT
Lec-12, 13 Quees - Circular Queues and Implementation with Array
PPT
Lec-32 Recursion - Divide and Conquer in Queue
PPT
Lec-32 Recursion -Recursion in Computer Science
PPT
Lec-32 What is recursion? A mathematical look
PPTX
The word or can be interpreted in two distinct ways:
PPTX
A proposition makes a claim (either an assertion or a denial) that may be eit...
Link List : Introduction to List and Linked Lists
Link List REPRESENTATION OF DOUBLY LINKED LIST
ALGORITHM FOR PUSHING AN ELEMENT TO A QUEUE
Link List STACK and Queue USING LINKED LIST
Link List Programming Linked List in Cpp
Link List & ALGORITHM FOR DELETING A NODE
Link List ALGORITHM FOR INSERTING A NODE
Presentations Linked Lists Data Structure
Lec-12, 13 Quees First In First Out (FIFO)
Lec-12, 13 Quee s Applications of Queues
Lec-12, 13 Quees Array Implementation IN
Lec-12, 13 Quees -How to determine empty and full Queues?
Unit2-BIS Business Information system Data
Lec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees - Circular Queues and Implementation with Array
Lec-32 Recursion - Divide and Conquer in Queue
Lec-32 Recursion -Recursion in Computer Science
Lec-32 What is recursion? A mathematical look
The word or can be interpreted in two distinct ways:
A proposition makes a claim (either an assertion or a denial) that may be eit...
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Classroom Observation Tools for Teachers
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
RMMM.pdf make it easy to upload and study
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharma ospi slides which help in ospi learning
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Lesson notes of climatology university.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Classroom Observation Tools for Teachers
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Complications of Minimal Access Surgery at WLH
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
RMMM.pdf make it easy to upload and study
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Microbial diseases, their pathogenesis and prophylaxis
Pharma ospi slides which help in ospi learning
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
A systematic review of self-coping strategies used by university students to ...
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx

Lec-12, 13 Quees A class for Dynamic Queue implementation

  • 1. A class for Dynamic Queue implementation class DynIntQueue { private: struct QueueNode { int value; QueueNode *next; }; QueueNode *front; QueueNode *rear; int numItems; public: DynIntQueue(void); ~DynIntQueue(void); void enqueue(int); int dequeue(void); bool isEmpty(void); void makeNull(void); };
  • 2. Implemenaton //************************ // Constructor * //************************ DynIntQueue::DynIntQueue(void) { front = NULL; rear = NULL; numItems = 0; } //************************ // Destructor * //************************ DynIntQueue::~DynIntQueue(void) { makeNull(); }
  • 3. //******************************************** // Function enqueue inserts the value in num * // at the rear of the queue. * //******************************************** void DynIntQueue::enqueue(int num) { QueueNode *newNode; newNode = new QueueNode; newNode->value = num; newNode->next = NULL; if (isEmpty()) { front = newNode; rear = newNode; } else { rear->next = newNode; rear = newNode; } numItems++; }
  • 4. //********************************************** // Function dequeue removes the value at the * // front of the queue, and copies it into num. * //********************************************** int DynIntQueue::dequeue(void) { QueueNode *temp; int num; if (isEmpty()) cout << "The queue is empty.n"; else { num = front->value; temp = front->next; delete front; front = temp; numItems--; } return num; }
  • 5. //********************************************* // Function isEmpty returns true if the queue * // is empty, and false otherwise. * //********************************************* bool DynIntQueue::isEmpty(void) { if (numItems) return false; else return true; }
  • 6. //******************************************** // Function makeNull dequeues all the elements * // in the queue. * //******************************************** void DynIntQueue::makeNull(void) { while(!isEmpty()) dequeue(); }
  • 7. Program // This program demonstrates the DynIntQeue class void main(void) { DynIntQueue iQueue; cout << "Enqueuing 5 items...n"; // Enqueue 5 items. for (int x = 0; x < 5; x++) iQueue.enqueue(x); // Deqeue and retrieve all items in the queue cout << "The values in the queue were:n"; while (!iQueue.isEmpty()) { int value; value =iQueue.dequeue(); cout << value << endl; } }
  • 8. Program Ouput Enqueuing 5 items... The values in the queue were: 0 1 2 3 4

Editor's Notes

  • #3: Visit: tshahab.blogspot.com