Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
47 views

Queue Using Array

This C program implements a queue using an array. It defines functions to insert, delete, and display items in the queue. The main function contains a menu to call these functions and a loop that runs until the user exits. The insert function adds an item to the rear of the queue if not full. The delete function removes an item from the front if not empty. And the display function prints all items currently in the queue.

Uploaded by

om shirdhankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Queue Using Array

This C program implements a queue using an array. It defines functions to insert, delete, and display items in the queue. The main function contains a menu to call these functions and a loop that runs until the user exits. The insert function adds an item to the rear of the queue if not full. The delete function removes an item from the front if not empty. And the display function prints all items currently in the queue.

Uploaded by

om shirdhankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>

#include<conio.h>

#define MAXSIZE 10

int queue[MAXSIZE],rear=-1, front=-1;

void Insert();

int Delete();

void display();

void main()

int ch;

clrscr();

printf("1.Insert\n2.Delete\n3.DISPLAY\n4.EXIT\n");

do

printf("\nEnter your choice: ");

scanf("%d",&ch);

switch(ch)

case 1:Insert();break;

case 2:Delete();break;

case 3:display();break;

case 4:printf("Program exited");break;

default:printf("Invalid choice");

}while(ch!=4);
}

void Insert()

if(rear == MAX-1)

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

else

printf("\n\nEnter ITEM: ");

scanf("%d", &item);

if (rear == -1 && front == -1)

rear = 0;

front = 0;

else

rear++;

queue[rear] = item;

printf("\n\nItem inserted: %d", item);

void delete()

if(front == -1)

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

else
{

item = queue[front];

if (front == rear)

front = -1;

rear = -1;

else

front++;

printf("\n\nItem deleted: %d", item);

void display()

int i;

if(front == -1)

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

else

printf("\n\n");

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

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

You might also like