0% found this document useful (0 votes)
4 views5 pages

Dynamic Double Ended Queue Implementation

Uploaded by

iqac
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)
4 views5 pages

Dynamic Double Ended Queue Implementation

Uploaded by

iqac
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

Dynamic Double Ended Queue.

struct DEQ
{
int info;
struct *next, *previous;
}*F,*R;

//Linked list implementation code to Insert at Front Side in a Double Ended


Queue
void insert_FRONT_DEQ( ) {
struct DEQ *insert;
int item;
insert = (struct DEQ*)malloc (sizeof(struct DEQ));
if(insert = = NULL) {
printf(“ \n Double ended Queue Overflow”);
}
else {
printf(“\n Enter the new element to inset in the DEQUEUE at FRONT Side”);
scanf(“%d”, &item);
if(F = = NULL and R = = NULL) {
F=R=insert;
}
else {
insert - > next = F;
insert - > previous = R;
R - > next = insert;
F - > previous = insert;
F = insert;
}
}
printf(“\n %d is inserted at Front Side in Double Ended Queue.”, F - > info);
}

// Linked list implementation code to delete at REAR Side in a Double Ended Queue.
void insert_REAR_DEQ( ) {
struct DEQ *insert;
int item;
insert = (struct DEQ*)malloc (sizeof(struct DEQ));
if(insert = = NULL)
{
printf(“ \n Double ended Queue Overflow”);
}
else {
printf(“\n Enter the new element to inset in the DEQUEUE at REAR Side”);
scanf(“%d”, &item);
if(F = = NULL and R = = NULL) {
F=R=insert;
}
else {
R - > next = insert;
Insert - > previous = R;
Insert - > next = F;
F - > previous = insert;
R = insert;
}
}
printf(“\n %d is inserted at REAR Side in Double Ended Queue.”, R - > info);
}

//Dynamic delete operation at FRONT side of Double Ended Queue.


void delete_FRONT_DEQ( ) {
struct DEQ *item;

if(F = = NULL) {
printf(“\n Double Ended Queue is Empty.”);
}
else if ( F = =R) {
item = F;
F = R = NULL;
printf(“\n %d is deleted from Double Ended Queue.”, item->info);
free(item);
}
else {
item = F;
F - > next - > previous = R;
R - > next = F - > next;
F = F - > next;
}
}
printf(“\n %d is inserted at REAR Side in Double Ended Queue.”, R - > info);
}

//Dynamic delete operation at REAR side of Double Ended Queue.


void delete_REAR_DEQ( ) {
struct DEQ *item;
if(F = = NULL) {
printf(“\n Double Ended Queue is Empty.”);
}
else if ( F = =R) {
item = F;
F = R = NULL;
printf(“\n %d is deleted at FRONT Side in Double Ended Queue.”, item - > info);
free(item);
}
else {
item = R;
R - > previous - > next = F;
F - > previous = R - > previous;
R = R - > previous;
printf(“\n %d is deleted at REAR Side in Double Ended Queue.”, item - > info);
free(item);
}
}
}
//Dynamic Display elements of a Double Ended Queue at FRONT Side in a Double
Ended Queue.

void display_DEQ_Front( ) {
struct DEQ *item;
if( F = = NULL) {
printf(“\n Double ended queue is empty.”);
}
else {
item=F;
do{
printf(“%d”, item - > info);
item = item - > next;
} while(item - > next ! = F);
}
}
//Dynamic Display the elements of a Double Ended Queue at REAR Side in a Double
Ended Queue.

void display_DEQ_Rear( ) {
struct DEQ *item;
if( R = = NULL) {
printf(“\n Double ended queue is empty.”);
}
else {
item=R;
do{
printf(“%d”, item - > info);
item = item - > previous;
} while(item - > next ! = R);
}
}

You might also like