0% found this document useful (0 votes)
7 views3 pages

Queue Implementation in C Using Arrays

This document contains a C program that implements a queue using arrays with basic operations such as enqueue, dequeue, and display. The program allows users to insert elements into the queue, delete elements from it, and display the current elements in the queue. It includes a menu-driven interface for user interaction and handles invalid options appropriately.

Uploaded by

swapna Narla
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)
7 views3 pages

Queue Implementation in C Using Arrays

This document contains a C program that implements a queue using arrays with basic operations such as enqueue, dequeue, and display. The program allows users to insert elements into the queue, delete elements from it, and display the current elements in the queue. It includes a menu-driven interface for user interaction and handles invalid options appropriately.

Uploaded by

swapna Narla
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

/* Queue using Arrays */

#include<stdio.h>
#include<conio.h>
#define MAX 50
void enqueue(int);
int dequeue();
void display();
int queue[MAX];
int front=-1,rear=-1;

void main()
{
int ele,dele,choice;
char ch;
clrscr();
do
{
printf("enter ur choice as... \[Link]\[Link]\[Link]\ninvalid\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter the element for insertion\n");
scanf("%d",&ele);
enqueue(ele);
display();
break;
case 2:
dele=dequeue();
printf("\n dele=%d\n",dele);
display();
break;
case 3:
display();
break;
default:
printf("Invalid option\n");
}
printf("\npress Y|y to continue....\n");
scanf(" %c",&ch);
}while(ch=='y'||ch=='Y');
getch();
}
void display()
{
int i=front;
printf("The list of queue elements are....\n");
while(i<=rear)
{
printf("%d->",queue[i]);
i=i+1;
}
printf("NULL\n");
}
void enqueue(int ele)
{
if(rear==MAX-1 && front==0)
{
printf("Queue is full\n");
exit(0);
}
else
{
if(front==-1 && rear==-1)
rear=front=0;
else
rear=rear+1;
queue[rear]=ele;
}
}
int dequeue()
{
int dele;
if(front==-1 && rear==-1)
dele=0;
else
{
dele=queue[front];
if(front==rear)
front=rear=-1;
else
front=front+1;
}
return dele;
}

You might also like