0% found this document useful (0 votes)
48 views

Q Program Using Array Implementation

This C program implements basic queue operations using an array: insertion, deletion, and display. It defines a queue as a fixed-size array with front and rear pointers to track the first and last elements. The main function contains a menu to call functions for each operation and check for overflow or underflow. The insert function adds elements to the rear, delete removes from the front, and display prints out the current queue contents.

Uploaded by

akurathikotaiah
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)
48 views

Q Program Using Array Implementation

This C program implements basic queue operations using an array: insertion, deletion, and display. It defines a queue as a fixed-size array with front and rear pointers to track the first and last elements. The main function contains a menu to call functions for each operation and check for overflow or underflow. The insert function adds elements to the rear, delete removes from the front, and display prints out the current queue contents.

Uploaded by

akurathikotaiah
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
You are on page 1/ 4

Write a c program queue operation using arrays

#include <stdio.h>
#include<stdlib.h>
#include <conio.h>
#define MAX 5
void insert();
void delete();
void display();

int queue_array[MAX];
int rear = - 1;
int front = 0;
int main()
{
int choice;
clrscr();
while (1)
{
printf("1.Insert element to queue\n");
printf("2.Delete element from queue \n");
printf("3.Display all elements of queue \n");
printf("4.Quit\n");
printf("Enter your choice :\n ");
scanf("%d", &choice);
switch(choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice\n");
}
}
}

void insert()
{
int item;
if(rear == MAX - 1)
printf("Queue Overflow\n");
else
{

printf("Inset the element in queue :\n ");


scanf("%d", &item);
rear = rear + 1;
queue_array[rear] = item;
}
}
void delete()
{
if((front == 0 )&&(rear==-1))
{
printf("Queue Underflow \n");
return;
}
else
if(front==rear)
{
printf("Element deleted from queue is : %d\n", queue_array[front]);
front=0;
rear=-1;
}
else
{
printf("Element deleted from queue is : %d\n", queue_array[front]);
front = front + 1;
}
}
void display()
{
int i;
if(front == 0)&&(rear==-1))
printf("Queue is empty \n");
else
{
printf("Queue is : \n");
for(i = front; i <= rear; i++)
printf("%d ", queue_array[i]);
printf("\n");
}
}

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