You are on page 1of 6

ASSIGNMENT-2

Name -ASHOK KUMAR


Roll no- BTECH/15249/19
Sem-3rd
Branch-IT
Sub-Data structure

Q1. What is deque? What are different types of deque?

Ans1.A deque is an ordered collection of items similar to the queue.


In data structure a double ended queue is an abstract data type that
generalize a circular queue for which elements can be added to or
removed
From either the front or back. It is also often called a head tailed linked
list.
There are two variation of a deque, which are intermediate between a
deque and a queue:
1.Input restricted deque: - this allows insertion only at one end but
allows deletion at both ends.
2.Output restricted deque: - this allows insertion at both ends but allows
deletion at only at one end.

Q2.Write a program to implement circular queue.


Ans 2: Circular queue

program:

#include<stdio.h>
#include<stdlib.h>
#define max 5
using namespace std;
void inser();
void delet();
void display();
int r=-1;
int f=0;
int count=0;
int a[max];
int main()
{
int choice;
printf("\n\t press 1:TO Insert");
printf("\n\t press 2:TO Delete");
printf("\n\t press 3:TO Display");
printf("\n\t press 4:EXIT");
for(;;)
{
printf("\nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
inser();
break;
case 2:
delet();
break;
case 3:
display();
break;
case 4:
exit(0);
}
}

return 0;
}

void inser()
{
if(count>max-1)
{
printf("\n queue overflow");
}
else{
if(r>max-1)
{
r=0;
}
printf("\nEnter the element to insert: ");
int n;
scanf("%d",&n);
r++;
a[r]=n;
count++;
}
}
void delet()
{
if(count==0)
{
printf("\n queue Underflow");
}
else {
if(f>max-1)
{
f=0;
}
printf("%d", a[f]);
printf(" Element is deleted from queue ");
f++;
count--;
}
}
void display()
{
if(count==-1)
{
printf("\n queue is empty");
}
if(r>=f)
{
for(int i=f;i<=r;i++)
{
printf("%d",a[i]);
printf(" ");

}
}
else
{
for(int i=f;i<=max-1;i++)
{
printf("%d",a[i]);
printf(" ");
}
for(int i=0;i<=r;i++)
{
printf("%d",a[i]);
printf(" ");
}
}
}

output:

You might also like