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

Practical - 4 .: Aim - Write A Program To Implement Queue

This program implements a queue using arrays in C. It defines functions to insert items into the queue, delete items from the queue, and display the queue. The main function runs a loop that prompts the user to insert or delete items and displays the results. The insert function adds an item to the rear of the queue if it is not full. The delete function removes an item from the front and updates the front and rear pointers.

Uploaded by

Manu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Practical - 4 .: Aim - Write A Program To Implement Queue

This program implements a queue using arrays in C. It defines functions to insert items into the queue, delete items from the queue, and display the queue. The main function runs a loop that prompts the user to insert or delete items and displays the results. The insert function adds an item to the rear of the queue if it is not full. The delete function removes an item from the front and updates the front and rear pointers.

Uploaded by

Manu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

PRACTICAL -- 4

AIM -- WRITE A PROGRAM TO IMPLEMENT QUEUE.


#include<stdio.h> #include<conio.h> void insert(); void deletion(); void entry(); int i,front=-1,rear=-1,choice,e,maxsize= 4,n,item,queue[4]; void main() { clrscr(); entry(); printf("\ndo you want continue yes or no "); scanf("%d",&e); switch(e) { case 1: entry(); break; default : printf("ok"); break; } getch(); } void entry() { printf("\n1. insert"); printf("\n2.delete"); printf("\n3.display"); printf("\nenter your choice"); scanf("%d",&n); switch(n) { case 1: insert(); break; case 2: deletion();

break; default: printf("choice invalid"); break; } } void insert() { if(rear==maxsize) printf("\nqueue is full"); else { if(rear==-1) { printf("\nenter the element to be inserted"); scanf("%d",&item); front=0; rear=0; queue[rear]=item; } else { printf("%d item to be inserted"); rear=rear+1; queue[rear]=item; } printf("item inserted\n\n"); printf("\nitem is %d",queue[rear]); } } void deletion() { if(front==-1) { printf("empty"); } else { if(rear==front) { item=queue[front];

rear=-1; front=-1; } else { item=queue[front]; front=front+1; } } printf("deleted item is%d",item); }

OUTPUT 1. insert 2.delete 3.display enter your choice1 enter the element to be inserted23 item inserted item is 23 do you want continue yes or no 1 1. insert 2.delete 3.display enter your choice 2 deleted item is 23

You might also like