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

Queue

Uploaded by

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

Queue

Uploaded by

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

Name: Saheranjum M.

Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

Q1. Write a program to using Queue.


#include<stdio.h>
#define size 5
int q[size],front=0,rear=-1;

int qfull()
{
if(rear==size-1)
return 1;
else
return 0;
}

int qempty()
{
if((front>rear)||(front==-1))
return 1;
else
return 0;
}

void insert(int item)


{
if(front==-1)
front++;
q[++rear]=item;
}

int del()
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

{
int item;
item=q[front];
front++;
return item;
}

void display()
{
int i;
if(qempty())
printf("q is empty");
for(i=front;i<=rear;i++)
printf("%d\t",q[i]);
}

int main()
{
int item,choice;
//clrscr();
printf("\nQUEUE\n");
do
{
printf("\n Enter your choice: \n 1 Add \n 2 Del \n 3 Display \n 4 Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

printf("Enter element to add\n");


scanf("%d",&item);
if(qfull())
printf("\n q is full");
else
insert(item);
break;
}
case 2:
{
if(qempty())
printf("\n q is empty");
else
{
item=del();
printf("\n Delete element is %d",item);
}
break;
}
case 3:
{
display();
break;
}
case 4:
printf("\n exit");
break;
}
}
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

while(choice!=4);
return 0;
}

OUTPUT:
Queue is empty:

Adding elements:
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

Queue is full:

Display elements:

Delete an element:

You might also like