Atif Jalal 02-235191-027 BS (IT) - 3A Lab 07 Date: 14 July, 2020
Atif Jalal 02-235191-027 BS (IT) - 3A Lab 07 Date: 14 July, 2020
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();
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 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: