Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Government Engineering College, Gandhinagar

Computer Engineering
B.E. Semester III
(AY 2021-22)
SUBJECT: Data Structures( 3130702)
Student Details:
Enrolment No. : D2D-40

Full Name : Gadesha Jay Kamleshbhai


(Surname Mid. First Name)

Sub-Division: CE-B3

Email Id: jaygadesha5437@gmail.com

Contact Number: 8866047039

Signatures:
Student:

Subject Coordinator/Lab Faculty:

HOD Signature:
Topics to be covered
Description of topic
Code
Output
Understanding/ problems

Aim: Write a program to implement QUEUE using arrays that performs following
operations: (a) INSERT (b) DELETE (c) DISPLAY
Description of topic:
 Ask the user for the operation like insert, delete, display and exit.
 According to the option entered, access its respective function using switch statement. Use
the variables front and rear to represent the first and last element of the queue.
 In the function insert(), firstly check if the queue is full. If it is, the print the output as
QUEUE IS FULL. Otherwise take a number to be inserted as input and store it in the
variable. Copy the variable to the array and increment the variable read by 1.
 In the function delete(), firstly check if the queue is empty. If it is, the print the output as
QUEUE IS EMPTY. Otherwise print the first element of the array and decrement the
variable front by 1.
 In the function display(), using if-else print all the elements of the array starting from front
to rear.
 Exit.

Code:
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>

#define MAX 3
int queue[MAX],front=-1,rear=-1;

void insert()
{

if(rear==MAX-1)
{
printf("queue is full\n");
}
else{
if(front==-1)
{
front=0;
}
int ele;
printf("Enter element:");
scanf("%d",&ele);

rear++;
queue[rear]=ele;

printf("\n%d inserted",ele);
}
}
void delete()
{

if(front==-1 || front>rear)
{
printf("queue is empty\n");
}
else{
printf("\n%d deleted",queue[front]);
front++;
}

}
void display()
{
if(front==-1)
{
printf("queue is empty\n");

else
{
if(front==-1)
{
front=0;
}
for(int i=front;i<=rear;i++)
{
printf("\n%d",queue[i]);
}
}
}

int main()
{
int gd=DETECT, gm;

int choice;
while (choice != 0)
{
printf("insert:1\n");
printf("delete:2\n");
printf("display:3\n");
printf("select queue operation:(PRESS 0 FOR EXIT):");
scanf("%d", &choice);

intitgraph(&gd, &gm, "C\\TURBOC3\\BGI");

switch (choice)
{

case 1:insert();
break;
case 2:delete();
break;
case 3:display();
break;
default:
printf("Please enter appropriate choice!\n");
break;
}
}

return 0;

closegraph();
}
Understanding:
What have you learned from this experiment?
Write an appropriate
(Tick ✔ the
Learning of answer in one
appropriate) or two words.
✔ Theoretical Concept
✔ Problem Solving
✔ Coding Style
✔ Testing
Way to answer a

question in exam

You might also like