0% found this document useful (0 votes)
11 views9 pages

Double Ended Queue

Uploaded by

alveenapbabu786
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)
11 views9 pages

Double Ended Queue

Uploaded by

alveenapbabu786
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/ 9

/***********************************************************************************/

Name : K. Yedukrishnan Date : 02/11/2023

DOUBLE ENDED QUEUE USING ARRAY

Roll:No : 42 Experiment No : 9

/***********************************************************************************/

PROGRAM

#include <stdio.h>

int a[20],size,front,rear;

void push_dq(int item)

int i;

if(front==0&&rear==size-1)

printf("\nDeque is full.");

else if(rear==-1&&front==-1)

front=rear=0;

a[front]=item;

else if(front>0)

front=front-1;

a[front]=item;

else

for(i=rear;i>=front;i--)

{
a[i+1]=a[i];

a[front]=item;

rear=rear+1;

void inject_dq(int item)

int i;

if(front==0&&rear==size-1)

printf("\nDeque is full.");

else if(rear==-1&&front==-1)

front=rear=0;

a[rear]=item;

else if(rear<size-1)

rear=rear+1;

a[rear]=item;

else

for(i=front;i<=rear;i++)

a[i-1]=a[i];

}
a[rear]=item;

front=front-1;

void pop_dq()

if(rear==-1&&front==-1)

printf("\nDeque is empty.");

else if(front==rear)

printf("\nPopped item is:%d",a[front]);

front=rear=-1;

else

printf("\nPopped item is:%d",a[front]);

front=front+1;

void eject_dq()

if(rear==-1&&front==-1)

printf("\nDeque is empty.");

else if(front==rear)

{
printf("\nEjected item is:%d",a[front]);

front=rear=-1;

else

printf("\nEjected item is:%d",a[rear]);

rear=rear-1;

void display_dq()

int i;

if(rear==-1&&front==-1)

printf("\nDeque is empty.");

else

for(i=front;i<=rear;i++)

printf("\t%d",a[i]);

void main()

int opt,item;

front=rear=-1;

printf("\nEnter the size of the queue:");


scanf("%d",&size);

do

printf("\nChoose an operation to
perform;\n(1)PUSH\n(2)POP\n(3)INJECT\n(4)EJECT\n(5)DISPLAY\n(6)EXIT\n");

scanf("%d",&opt);

switch(opt)

case 1:printf("\nEnter the item to be pushed:");

scanf("%d",&item);

push_dq(item);

break;

case 2:pop_dq();

break;

case 3:printf("\nEnter the item to be injected:");

scanf("%d",&item);

inject_dq(item);

break;

case 4:eject_dq();

break;

case 5:display_dq();

break;

case 6:break;

default:printf("\nInvalid option.");

}while(opt!=6);

}
/***********************************************************************************/

OUTPUT
Enter the size of the queue:3

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Enter the item to be pushed:2

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Enter the item to be injected:3

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Enter the item to be pushed:4

Choose an operation to perform;


(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Enter the item to be injected:6

Deque is full.

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

4 2 3

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Popped item is:4

Choose an operation to perform;

(1)PUSH
(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Ejected item is:3

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Popped item is:2

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

Deque is empty.

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT
(4)EJECT

(5)DISPLAY

(6)EXIT

Deque is empty.

Choose an operation to perform;

(1)PUSH

(2)POP

(3)INJECT

(4)EJECT

(5)DISPLAY

(6)EXIT

/***********************************************************************************/

You might also like