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

Priority Queue Using Linked List

The document presents a C++ implementation of a priority queue using a linked list. It includes methods for enqueueing, dequeueing, displaying the queue, and maintaining priority order. The main function provides a user interface for interacting with the priority queue through a menu-driven approach.

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)
10 views

Priority Queue Using Linked List

The document presents a C++ implementation of a priority queue using a linked list. It includes methods for enqueueing, dequeueing, displaying the queue, and maintaining priority order. The main function provides a user interface for interacting with the priority queue through a menu-driven approach.

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

Priority Queue Using Linked List

#include<iostream>

#include<conio.h>

using namespace std;

int count = 0;

class Node

public:

int data;

Node *next_add;

};

class Linked_List

private:

Node *Head;

Node *Tail;

public:

Linked_List()

Head = NULL;

Tail = NULL;

void Enqueue(int value)

{
Node *newNode = new Node;

newNode -> data = value;

newNode -> next_add = NULL;

if(Head == NULL)

Head = newNode;

Tail = newNode;

else

Tail -> next_add = newNode;

Tail = newNode;

Priority_Queue();

count++;

cout<<"\n\n *** Node "<<value<<" Value Enqueue Successfully ***";

void Dequeue()

if(Head == NULL)

cout<<"\n\n *** Linked List is Empty ***";

else

{
Node *ptr = Head;

Head = Head -> next_add;

cout<<"\n\n *** Node "<<ptr -> data<<" Value Dequeue


Successfully ***";

delete ptr;

void Display()

if(Head == NULL)

cout<<"\n\n *** Linked List Is Empty ***";

else

cout<<"\n\n PRIORITY QUEUE : ";

Node *ptr = Head;

while(ptr != NULL)

cout<<ptr -> data<<" ";

ptr = ptr -> next_add;

void Priority_Queue()
{

int temp;

for(int i=1; i<=count; i++)

Node *ptr = Head;

for(int j=1; j<=count; j++)

if(ptr -> data < ptr -> next_add -> data)

temp = ptr -> data;

ptr -> data = ptr -> next_add -> data;

ptr -> next_add -> data = temp;

ptr = ptr -> next_add;

~Linked_List()

{}

};

main()

Linked_List List;

while(1)

{
system("cls");

int choice,value;

cout<<"\n **** 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\n ENTER VALUE -> ";

cin>>value;

List.Enqueue(value);

break;

case 2:

List.Dequeue();

break;

case 3:

List.Display();

break;

case 4:

exit(0);

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

getch();

You might also like