0% found this document useful (0 votes)
71 views

Dsa Lab 7 Aiman

The document describes a lab assignment to implement a queue using an array. It provides the functions to be included: enqueue to add an element, dequeue to remove an element, and displayQueue to output the queue. It gives sample test code adding several elements and calling the functions. It then provides the C++ code implementation of the queue with functions for the queue operations and a main function to test it in a menu-driven program.

Uploaded by

Aiman Fareed
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)
71 views

Dsa Lab 7 Aiman

The document describes a lab assignment to implement a queue using an array. It provides the functions to be included: enqueue to add an element, dequeue to remove an element, and displayQueue to output the queue. It gives sample test code adding several elements and calling the functions. It then provides the C++ code implementation of the queue with functions for the queue operations and a main function to test it in a menu-driven program.

Uploaded by

Aiman Fareed
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/ 6

CSL-221:Data Structures & Algorithms

Semester BS CS – 03 & BS IT - 03

LAB An array based implementation of QUEUE with the


help of algorithm for following functions
07 •

enQueue()
deQueue()
 displayQueue()

Lab Task(s):

Write a program as follows for QUEUE


1

----------------------Array based implementation of QUEUE-----------------------------------

1. Enqueue an element to queue


2. Dequeue an element from queue
3. Display all
4. Exit
-------------------------------------------------------------------------------------------------------------

Please Enter Your Choice:

Test the program using the following procedure: QUEUE of size N=6
2
Call enQueue(5)
Call enQueue(2)
Call enQueue(3)
Call deQueue ()
call deQueue()
CSL-221:Data Structures & Algorithms
Semester BS CS – 03 & BS IT - 03

Call enQueue(6)
Call enQueue(3)
Call Display()

#include<iostream>

#define Size 6

using namespace std;

int Que[Size], Front = 0, Rear = 0;

int Is_Empty()

if(Front == Rear)

return 1;

else

return 0;

int Is_Full()
CSL-221:Data Structures & Algorithms
Semester BS CS – 03 & BS IT - 03

if(Size == Rear && Front == 0)

return 1;

else

return 0;

void Enque(int value)

if(Is_Full())

cout << "Que is full" << endl;

return;

else

Que[Rear] = value;

Rear++;

cout << value << " value is enqeue in array" << endl;

void Deque()

int no;
CSL-221:Data Structures & Algorithms
Semester BS CS – 03 & BS IT - 03

if(Is_Empty())

cout << "Que is empty" << endl;

return;

else

no = Que[Front];

Front++;

cout << no <<" is deleted from que. " << endl;

void Display()

if(Is_Empty())

cout << "Que is empty" <<endl;

return;

else

for(int i = Front; i < Rear; i++)

cout << Que[i]<<" ";

cout<<endl;

}
CSL-221:Data Structures & Algorithms
Semester BS CS – 03 & BS IT - 03

int main()

int Choice, Value;

while(Choice != 4)

cout << "Choose (1):Enque Element (2):Deque Element (3):Display (4):Exit" << endl;

cout << "Enter your choice: ";

cin >> Choice;

switch(Choice)

case 1:

cout << "Enter Value: ";

cin >> Value;

Enque(Value);

break;

case 2:

Deque();

break;

case 3:

Display();

break;

case 4:

break;

default :
CSL-221:Data Structures & Algorithms
Semester BS CS – 03 & BS IT - 03

cout<<"invalid"<<endl;

return 0;

You might also like