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

Double Ended Queue Using Array

This C program implements a queue using an array. It defines functions for insertion and deletion at both the front and rear of the queue, as well as a display function. The main function uses a switch statement to call the appropriate function based on the user's menu choice and loops until the user chooses to exit.

Uploaded by

om shirdhankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Double Ended Queue Using Array

This C program implements a queue using an array. It defines functions for insertion and deletion at both the front and rear of the queue, as well as a display function. The main function uses a switch statement to call the appropriate function based on the user's menu choice and loops until the user chooses to exit.

Uploaded by

om shirdhankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h>

#include<conio.h>

#define MAXSIZE 10

void insertion_rear();

void insertion_front();

void deletion_rear();

void deletion_front();

void display();

int rear=-1,front=0,q[MAXSIZE];

void main()

int choice;

clrscr();

printf("1.insertion_rear\n2.insertion_front\n3.deletion_rear\n4.deletion_front\n5.display\n6.exit\n ");

do

printf("\nEnter your choice: ");

scanf("%d",&choice);

switch(choice)

case 1:insertion_rear();break;

case 2:insertion_front();break;

case 3:deletion_rear();break;

case 4:deletion_front();break;

case 5:display();break;
case 6:printf("Program exited");break;

default:printf("Invalid choice");

}while(choice!=6);

void insertion_rear()

int element;

if(rear>=MAXSIZE-1)

printf("Queue is full");

else

printf("Enter element to be added: ");

scanf("%d",&element);

rear++;

q[rear]=element;

void deletion_rear()

int element;

if(rear<front)

printf("Queue is empty");

else

{
element=q[rear];

rear--;

printf("The deleted element is %d",element);

void deletion_front()

int element;

if(rear<front)

printf("Queue is empty");

else

element=q[front];

front++;

printf("The deleted element is %d",element);

void insertion_front()

int element;

if(front==0)

printf("Queue is full");

else

printf("Enter element to be added: ");


scanf("%d",&element);

front--;

q[front]=element;

void display()

int i;

if(rear<front)

printf("Queue is empty");

else

printf("Elements are \t");

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

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

You might also like