0% found this document useful (0 votes)
60 views4 pages

Atif Jalal 02-235191-027 BS (IT) - 3A Lab 07 Date: 14 July, 2020

The document describes a C++ program that implements an array-based queue data structure. The program contains functions for enqueueing, dequeueing, checking if the queue is full or empty, and displaying the queue. It uses arrays, front and rear pointers, and a menu-driven system to allow a user to test the queue operations by entering choices to add or remove elements and display the queue.

Uploaded by

Atif Jalal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views4 pages

Atif Jalal 02-235191-027 BS (IT) - 3A Lab 07 Date: 14 July, 2020

The document describes a C++ program that implements an array-based queue data structure. The program contains functions for enqueueing, dequeueing, checking if the queue is full or empty, and displaying the queue. It uses arrays, front and rear pointers, and a menu-driven system to allow a user to test the queue operations by entering choices to add or remove elements and display the queue.

Uploaded by

Atif Jalal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Atif Jalal

02-235191-027
BS (IT)-3A Lab 07 Date: 14 July, 2020

Exercise 1:
Source Code:
#include <iostream>
using namespace std;

void enqueue(int);
bool isfull();
void dequeue();
bool isempty();
void display();

int queue[6], size = 6, front = -1, rear = -1;


Atif Jalal
02-235191-027
BS (IT)-3A Lab 07 Date: 14 July, 2020

void main()
{
int a = 0, b;
cout << "\n ------------------ ARRAY BASED QUEUE ------------------" << endl;
cout << " 1. Enqueue an element to Queue \n 2. Dequeue an element from Queue "
<< endl;
cout << " 3. Display \n 4. Exit" << endl;
cout << " -------------------------------------------------------" << endl;
while (a != 4)
{
cout << "\n Enter your choice : ";
cin >> a;
switch (a)
{
case 1:
{
cout << " Enter number : ";
cin >> b;
enqueue(b);
break;
}
case 2:
{
dequeue();
break;
}
case 3:
{
display();
break;
}
case 4:
{
break;
}
default:
cout << "\n Select from the given (1-4) options." << endl;
}
}
system("pause");
}

void enqueue(int value)


{
if (isempty())
{
front = 0;
rear = 0;
queue[rear] = value;
}
else if(isfull())
{
cout << "\n Stack overflow." << endl;
}
else
{
rear++;
queue[rear] = value;
}
}
Atif Jalal
02-235191-027
BS (IT)-3A Lab 07 Date: 14 July, 2020
bool isfull()
{
if (rear == 5)
return true;
else
return false;
}

void dequeue()
{
if (isempty())
{
cout << "\n Queue underflow." <<endl;
}
else if (front == rear)
{
front = -1;
rear = -1;
}
else
{
front++;
}
}

bool isempty()
{
if (front == -1 && rear == -1)
return true;
else
return false;
}
void display()
{
cout << " Queue : {";
for (int i = front; i <= rear; i++)
{
cout << queue[i] << ",";
}
cout << "\b}" << endl;
}
Atif Jalal
02-235191-027
BS (IT)-3A Lab 07 Date: 14 July, 2020
Output:

You might also like