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

Prg_5

The document outlines a C program for performing queue operations using arrays, including insertion, deletion, and display functions. It provides an algorithm for each operation and includes the complete code for the program. The program allows users to interactively manage a queue with options to insert, delete, and display elements until they choose to exit.

Uploaded by

darkface00505
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)
3 views5 pages

Prg_5

The document outlines a C program for performing queue operations using arrays, including insertion, deletion, and display functions. It provides an algorithm for each operation and includes the complete code for the program. The program allows users to interactively manage a queue with options to insert, delete, and display elements until they choose to exit.

Uploaded by

darkface00505
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/ 5

Sss

QUEUE OPERATIONS
5. Write a C Program to perform QUEUE operations using Arrays

AIM :
To write a C Program to perform Queue operations using Arrays

ALGORITHM :
Insert()
Step 1: Start
Step 2: If front = NULL
front = rear = 0
queue[front]=element
Stop
Step 3: if rear = MAX-1
Display the message, “Queue is Full” and
Stop
Step 4: rear = rear +1
Step 5: queue[rear] = element
Step 6: Stop
Delete()
Step 1: Start
Step 2: if front = NULL and rear = NULL
Display the message, “Queue is Empty”
And Stop
Step 3: if front = rear
Set i = queue[front]
Set front = rear = NULL
Return the deleted element i and
Stop
Step 4: Set i = queue[front]
SteP 5: front++;
Step 5: Return the deleted element i
Step 6: Stop

PROGRAM :
#include <stdio.h>
#include<conio.h>
void insert();
void delete();
void display();
int queue_array[100],x,i,choice,n;
int rear = - 1;
int front = - 1;
void main()
{
clrscr();
printf("\n Enter the size of QUEUE[MAX=100]:");
scanf("%d", &n);
do
{
clrscr();
printf("\n\n\t\t\tQUEUE OPERATION USING ARRAY");
printf("\n\t\t\t----------------------------");
printf("\n\n\t\t\t 1.INSERT");
printf("\n\t\t\t 2.DELETE");
printf("\n\t\t\t 3.DISPLAY");
printf("\n\t\t\t 4.EXIT");
printf("\n\t\t\tENTER CHOICE : ");
scanf("%d",&choice);
switch(choice)
{
case 1: insert();
break;
case 2: delete();
break;
case 3: display();
break;
case 4: printf("\n\t\t\tEXIT POINT");
break;
default: printf("\n\t\t\tINVALID CHOICE");
}
} while(choice!=4);
}

void insert()
{
if (rear >= n - 1)
{
printf("\n\t\t\tQUEUE OVERFLOW\n");
}
else
{
if (front == - 1)
{
front = 0;
}
printf("\n\t\t\tENTER ELEMENT TO BE INSERTED : ");
scanf("%d", &x);
rear = rear + 1;
queue_array[rear] = x;
printf("\n\t\t\tELEMENT INSERTED…");
getch();
}
}

void delete()
{
if (front <= - 1 || front > rear)
{
printf("\n\t\t\tQUEUE UNDERFLOW");
return ;
}
else
{
printf("\n\t\t\tDELETED ELEMENT : %d",queue_array[front]);
front = front + 1;
}
getch();
}
void display()
{
int i;
if (front >= 0)
{
printf("\n\t\t\tELEMENTS IN QUEUE : \n");
for(i=front; i<=rear; i++)
{
printf("\n\t\t\t%d ",queue_array[i]);
}
}
else
{
printf("\n\t\t\tQUEUE IS EMPTY");
}
getch();
}

OUTPUT :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy