0% found this document useful (0 votes)
20 views3 pages

Priority Queue - Arrays

Uploaded by

Harsh Singh
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)
20 views3 pages

Priority Queue - Arrays

Uploaded by

Harsh Singh
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

#include <stdio.

h>

#include <stdlib.h>

#define SIZE 5

int rear=-1,front=-1;

int q[SIZE];

void insert(int item)

int pos;

if(rear==SIZE-1)

printf("queue is full\n");

else{

pos=rear;

rear=rear+1;

while(pos>=0&&q[pos]>=item)

q[pos+1]=q[pos];

pos=pos-1;

q[pos+1]=item;

if(front==-1)front=front+1;

void delet()

int del;

if(front==-1)printf("queue empty\n");
else{

del=q[front];

printf("deleted item is %d\n",del);

if(front==rear){

front=-1;

rear=-1;

else{

front=front+1;

void display()

int i;

if(front==-1)printf("queue empty\n");

else{

printf("queue elements are\n");

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

printf("%d\t",q[i]);

int main()

int ch,item;

for(;;) //infinite loop

printf("\n 1. insert");

printf("\n 2. delete");

printf("\n 3. display");
printf("\n 4. exit");

printf("\n read choice");

scanf("%d",&ch);

switch(ch)

case 1: printf("enter item\n");

scanf("%d",&item);

insert(item);

break;

case 2: delet();

break;

case 3: display();

break;

default: exit(0);

return 0;

You might also like