0% found this document useful (0 votes)
22 views4 pages

Priority Queue Using Array

The document presents a C++ implementation of a priority queue using an array. It includes functions for enqueueing, dequeueing, and displaying elements, while ensuring that the highest priority elements are at the front of the queue. The program runs in a loop, allowing the user to interactively choose operations until they decide to exit.

Uploaded by

eshafatima0877
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)
22 views4 pages

Priority Queue Using Array

The document presents a C++ implementation of a priority queue using an array. It includes functions for enqueueing, dequeueing, and displaying elements, while ensuring that the highest priority elements are at the front of the queue. The program runs in a loop, allowing the user to interactively choose operations until they decide to exit.

Uploaded by

eshafatima0877
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

Priority Queue Using Array

#include<iostream>

#include<conio.h>

using namespace std;

int i=0,j=0,array[5];

void PriorityQueue()

for(int a=j; a<i; a++)

for(int b=j; b<i-1; b++)

if(array[b] < array[b+1])

array[b] = array[b] + array[b+1];

array[b+1] = array[b] - array[b+1];

array[b] = array[b] - array[b+1];

void Enqueue(int value)

if(i >= 5)

cout<<"\n\n**** QUEUE IS FULL ****";


}

else

array[i] = value;

cout<<"\n\nENQUEUE "<<array[i];

i++;

PriorityQueue();

void Dequeue()

if(i == 0 || j == 5)

cout<<"\n\n**** QUEUE IS EMPTY *****";

else

cout<<"\n\n DEQUEUE "<<array[j++];

void Display()

if(i == 0 || j == 5)

cout<<"\n\n**** QUEUE IS EMPTY *****";


}

else

for(int a=j; a<i; a++)

cout<<"\n\n Priority Queue : "<<array[a]<<" ";

main()

while(1)

system("cls");

int choice,value;

cout<<"**** QUEUE WITH ARRAY ****\n\n";

cout<<"1) ENQUEUE\n\n";

cout<<"2) DEQUEUE\n\n";

cout<<"3) DISPLAY\n\n";

cout<<"4) EXIT\n\n";

cout<<"5) ENTER YOUR CHOICE -> ";

cin>>choice;

switch(choice)

case 1:
cout<<"\n\nENTER VALUE -> ";

cin>>value;

Enqueue(value);

break;

case 2:

Dequeue();

break;

case 3:

Display();

break;

case 4:

exit(0);

default:

cout<<"**** SORRY WRONG CHOICE****";

getch();

You might also like