0% found this document useful (0 votes)
59 views8 pages

Queue Implementation

The document defines a queue as a linear data structure where elements can be inserted at the rear and deleted from the front, following FIFO (First In First Out) order. It describes queue operations like enqueue to insert an element, dequeue to delete an element, and traverse to display all elements. The document also provides an implementation of a queue using arrays in C, including functions for enqueue, dequeue, and traverse while handling overflow and underflow conditions.

Uploaded by

Dinti Sai
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)
59 views8 pages

Queue Implementation

The document defines a queue as a linear data structure where elements can be inserted at the rear and deleted from the front, following FIFO (First In First Out) order. It describes queue operations like enqueue to insert an element, dequeue to delete an element, and traverse to display all elements. The document also provides an implementation of a queue using arrays in C, including functions for enqueue, dequeue, and traverse while handling overflow and underflow conditions.

Uploaded by

Dinti Sai
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
You are on page 1/ 8

QUEUES:

QUEUE ADT(Abstract Data Type)


{
Definition: queue it is a linear data strucuture. one
can insert or delete the elements at two endsthose
are called ‘FRONT’ nad ‘REAR’.REAR is used to insert
the new element and FRONT is used to delete the
element from queue.we also called the queue with
another name FIFO(First In First OUT).

Preconditions:

1)Q_full():it is a precondition. it is telling that whether


Queue is full or not.
2)Q_empty(): it is a precondition. it is telling that
whether queue is empty or not.
operations:
1)Enqueue():inserting the element into the Queue is
called Enqueue.
Before Performing this Enqueue opertaion
whether Queue is full or not.
if Queue is full we unable to perform Enqueue()
operarion. this condition is called Queue OVERFLOW.

2)Dequeue(): Deleting the element from the Queue is


called Dequeue.
Before perfroming Dequeue operation whether
Queue is empty or not.
if Queue is empty we unable to perform Dequeue
operarion.
this condition is called Queue UNDER FLOW.
4)traverse(): dispalying all the elements from the
Queue.

Queues using arrays program:

#include<stdio.h>
#define size 5
int qu[size],ele;
int front=-1,rear=-1;
void enque(int);
void deque();
void traverse();
void main()
{
int ch,item;
clrscr();
while(1)
{
printf("*****QUEUE
IMPLEMENTATION*****\n");
printf("1.ENQUEUE\n");
printf("2.DEQUEUE\n");
printf("3.TRAVERSE\n");
printf("4.EXIT\n");
printf("ENTER THE CHOICE\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nenter the element to enque:");
scanf("%d",&item);
enque(item);
break;
case 2: deque();
break;
case 3: traverse();
break;
case 4: exit(0);
default: printf("INVALID CHOICE\n");
}
}
getch();
}
void enque(ele)
{
if(rear==size-1)
{
printf("\nQUEUE IS OVERFLOW\n");
}
else if(front==-1 && rear==-1)
{
front=0;
rear=0;
qu[rear]=ele;
printf("INSERTED ELE IS %d\n",ele);
}
else
{
if(rear<size)
{
rear++;
qu[rear]=ele;
printf("INSERTED ELE IS %d\n",ele);
}
}
}
void deque()
{
if(front==-1 && rear==-1)
{
printf("\nUNDER FLOW\n");
}
else
{
ele=qu[front];
printf("DELETED ELE IS %d\n",ele);
front++;
if(front>rear)
{
front=-1;
rear=-1;
}
}
}
void traverse()
{
if(front==-1 && rear==-1)
{
printf("\nQUEUE IS UNDER FLOW\n");
}
else
{
int i;
for(i=front;i<=rear;i++)
{
printf("\n%d\t",qu[i]);
}
}
}

Void enque(ele)
{
If (rear==size-1)
Over flow

}
Void deque()
{
If(front==rear==-1)
{
Under flow
}
Else if(front==size-1 && rear!=size-1)
{
Ele=cq[front];
Front=0;
}
Else
{
Ele=cq[front];
Front++;
If(front==rear)
Front=-1
Rear=-1

You might also like