Doubly Queue - Merged
Doubly Queue - Merged
h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
void deleteFront() {
if (front == NULL) {
printf("Deque is empty!\n");
return;
}
struct Node* temp = front;
front = front->next;
if (front != NULL) front->prev = NULL;
else rear = NULL;
free(temp);
}
void deleteRear() {
if (rear == NULL) {
printf("Deque is empty!\n");
return;
}
struct Node* temp = rear;
rear = rear->prev;
if (rear != NULL) rear->next = NULL;
else front = NULL;
free(temp);
}
void displayDeque() {
struct Node* temp = front;
if (temp == NULL) {
printf("Deque is empty!\n");
return;
}
while (temp) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
Output :
int main() {
int choice, value;
do {
printf("\nMenu:\n1. Insert Front\n2. Insert Rear\n3. Delete
Front\n4. Delete Rear\n5. Display\n6. Exit\nEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter value to insert at front: ");
scanf("%d", &value);
insertFront(value);
break;
case 2:
printf("Enter value to insert at rear: ");
scanf("%d", &value);
insertRear(value);
break;
case 3:
deleteFront();
break;
case 4:
deleteRear();
break;
case 5:
displayDeque();
break;
case 6:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
}
} while (choice != 6);
return 0;
}