0% found this document useful (0 votes)
27 views6 pages

21bce133 Dsa 3b

The document contains the implementation of a priority queue using a 2D array. It defines functions to insert elements into the queue based on priority, delete elements from the queue based on priority, and display the elements of the queue. The main function initializes the queue to empty, takes user input for insert, delete, display or exit options, and calls the corresponding functions.

Uploaded by

Manan Ladani
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)
27 views6 pages

21bce133 Dsa 3b

The document contains the implementation of a priority queue using a 2D array. It defines functions to insert elements into the queue based on priority, delete elements from the queue based on priority, and display the elements of the queue. The main function initializes the queue to empty, takes user input for insert, delete, display or exit options, and calls the corresponding functions.

Uploaded by

Manan Ladani
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/ 6

Name : Ladani Manan Bhaveshkumar

Course : DSA

Roll no. : 21BCE133

Practical : 3B

Write a program to implement priority queue using 2D array.

Implementation :

#include <stdio.h>

#include <stdlib.h>

#define size 3

int front[size]={-1,-1,-1};

int rear[size]={-1,-1,-1};

char queue[size][size];

void Insert();

void Delete();

void Show();

void Insert()

int priority;

char Ele;

printf("Enter the priority (0-2): ");

scanf("%d", &priority);

printf("Enter the Element : ");

scanf(" %c", &Ele);

if(rear[priority]==size-1)
printf("Overflow......");

else{

if(rear[priority]==-1 && front[priority]==-1){

rear[priority]++;

front[priority]++;

else

rear[priority]++;

queue[priority][rear[priority]]=Ele;

printf("Element is inserted .....\n");

void Delete()

int priority;

printf("enter a priority number that you want to Delete (0-2) : ");

scanf("%d",&priority);

if(front[priority]==rear[priority]+1){

printf("There is no Element in this priority : \n");

return;

else{

queue[priority][front[priority]]='_';

front[priority]++;

printf("Element is Deleted \n ");

}
void Show()

for(int i=0;i<size;i++){

for(int j=0;j<size;j++){

printf("%c ",queue[i][j]);

printf("\n");

return;

int main()

for(int i=0;i<size;i++){

for(int j=0;j<size;j++){

queue[i][j]='_';

while(1){

int choice;

printf("1. Insert Element : \n");

printf("2. Delete Element : \n");

printf("3. Show Elements : \n");

printf("4. exit : \n");

scanf("%d", &choice);

switch(choice){

case 1:

Insert();

break;

case 2:
Delete();

break;

case 3:

Show();

break;

case 4:

exit(0);

break;

default:

printf("Invalid !!!");

return 0;

}
Output :

You might also like