0% found this document useful (0 votes)
36 views4 pages

C Queue Implementation in C

This document contains a C program that implements a basic queue data structure with operations such as enqueue, dequeue, check if empty or full, and display the queue. It defines a maximum size for the queue and uses an array to store the elements along with front and rear pointers. The program includes a menu-driven interface for user interaction to perform various queue operations.

Uploaded by

ericaprasad01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

C Queue Implementation in C

This document contains a C program that implements a basic queue data structure with operations such as enqueue, dequeue, check if empty or full, and display the queue. It defines a maximum size for the queue and uses an array to store the elements along with front and rear pointers. The program includes a menu-driven interface for user interaction to perform various queue operations.

Uploaded by

ericaprasad01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <stdio.

h>

#include <stdlib.h>

#define MAX_SIZE 10

// Define the maximum size for the queue

#define MAX_QUEUE_SIZE 10

// Global queue array and front/rear pointers

int queue[MAX_QUEUE_SIZE];

int front = -1;

int rear = -1;

// Function to check if the queue is empty

int isEmpty() {

return front == -1;

// Function to check if the queue is full

int isFull() {

return (rear == MAX_QUEUE_SIZE - 1);

// Function to enqueue an element into the queue

void enqueue(int data) {

if (isFull()) {

printf("Queue is full. Cannot enqueue element.\n");

return;

if (isEmpty()) {
front = 0;

queue[++rear] = data;

printf("Enqueued element: %d\n", data);

// Function to dequeue an element from the queue

void dequeue() {

if (isEmpty()) {

printf("Queue is empty. Cannot dequeue element.\n");

return;

int data = queue[front];

if (front == rear) {

front = rear = -1;

} else {

front++;

printf("Dequeued element: %d\n", data);

// Function to display the elements in the queue

void display() {

if (isEmpty()) {

printf("Queue is empty.\n");

return;

}
printf("Queue: ");

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

printf("%d ", queue[i]);

printf("\n");

int main() {

int choice, data;

while (1) {

printf("\nMenu:\n");

printf("1. Enqueue\n");

printf("2. Dequeue\n");

printf("3. Is Empty\n");

printf("4. Is Full\n");

printf("5. Display\n");

printf("6. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("Enter data to enqueue: ");

scanf("%d", &data);

enqueue(data);

break;

case 2:

dequeue();

break;

case 3:
if (isEmpty()) {

printf("Queue is empty.\n");

} else {

printf("Queue is not empty.\n");

break;

case 4:

if (isFull()) {

printf("Queue is full.\n");

} else {

printf("Queue is not full.\n");

break;

case 5:

display();

break;

case 6:

exit(0);

default:

printf("Invalid choice. Please try again.\n");

return 0;

You might also like