SlideShare a Scribd company logo
1 of 9
I need help with implementing the priority queue data structure with a linked list implementation
and with modifying my code with a template. Make sure that the code has the required methods
to get the given test code in driver.cpp to work properly. I will provide the main cpp file and
what I have so far below. The code is in C++. Add comments to where you modified the code, so
I know what you did to change it. Thank you.
//////////////////////// driver.cpp /////////////////////////////
#include <iostream>
#include <string>
#include "stackLL.h"
#include "queueLL.h"
#include "priorityQueueLL.h"
using namespace std;
int main()
{
/////////////Test code for stack ///////////////
stackLL stk;
stk.push(5);
stk.push(13);
stk.push(7);
stk.push(3);
stk.push(2);
stk.push(11);
cout << "Popping: " << stk.pop() << endl;
cout << "Popping: " << stk.pop() << endl;
stk.push(17);
stk.push(19);
stk.push(23);
while (!stk.empty())
{
cout << "Popping: " << stk.pop() << endl;
}
// output order: 11,2,23,19,17,3,7,13,5
stackLL stkx;
stkx.push(5);
stkx.push(10);
stkx.push(15);
stkx.push(20);
stkx.push(25);
stkx.push(30);
stkx.insertAt(-100, 3);
stkx.insertAt(-200, 7);
stkx.insertAt(-300, 0);
//output order: -300,30,25,20,-100,15,10,5,-200
while (!stkx.empty())
cout << "Popping: " << stkx.pop() << endl;
///////////////////////////////////////
//////////Test code for queue ///////////
queueLL Q;
Q.enqueue(1);
Q.enqueue(2);
Q.enqueue(3);
cout << "Dequeuing: " << Q.dequeue() << endl; //1
cout << "Dequeuing: " << Q.dequeue() << endl; //2
Q.enqueue(4);
Q.enqueue(5);
//3 4 5
while (!Q.empty())
{
cout << "Dequeuing: " << Q.dequeue() << endl;
}
/////////////////////////////////////////
//////////Test code for priority queue/////
priorityQueueLL<int> pQueue;
const int SIZE = 20;
//insert a bunch of random numbers
for (int i = 0; i < SIZE; i++)
{
pQueue.insert(rand());
}
//pull them back out..
//They must come out in order from smallest to largest
while (!pQueue.empty())
{
cout << pQueue.extractMin() << endl;
}
priorityQueueLL<string> pqs;
pqs.insert("whale");
pqs.insert("snake");
pqs.insert("buffalo");
pqs.insert("elmo");
pqs.insert("fire");
pqs.insert("waffle");
//buffalo elmo fire snake waffle whale
while (!pqs.empty())
{
cout << pqs.extractMin() << endl;
}
///////////////////////////////////////////
//1) Template your queue class
//2) Add a decimate method to your queue class
queueLL<int> qx;
for (int i = 1; i <= 100; i++)
qx.enqueue(i);
//Eliminate every 10th item from list
//https://en.wikipedia.org/wiki/Decimation_(punishment)
qx.decimate();
//1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 21 22... 98 99
while (!qx.empty())
cout << qx.dequeue() << endl;
queueLL<string> qy;
qy.enqueue("sparticus");
qy.enqueue("maximus");
qy.enqueue("killicus");
qy.enqueue("awesomeicus");
qy.enqueue("gannicus");
qy.enqueue("varro");
qy.enqueue("oenomous");
qy.enqueue("slayicus");
qy.enqueue("bladeicus");
qy.enqueue("ted");
qy.enqueue("smashicus");
qy.enqueue("mallicus");
qy.enqueue("wussicus");
qy.enqueue("wimpicus");
qy.enqueue("crixus");
qy.decimate();
//Everyone but Ted.
while (!qy.empty())
cout << qy.dequeue() << endl;
return 0;
}
//////////////////////// queueLL.h ///////////////////////////
#ifndef QUEUELL_H
#define QUEUELL_H
class queueLL
{
private:
//put what you need here...
public:
queueLL()
{}
~queueLL()
{}
//return true if empty, false if not
bool empty()
{}
//add item to back of queue
void enqueue(int x)
{}
//remove and return first item from queue
int dequeue()
{}
//For the final part of the test program, template this class
//and add a decimate method.
};
#endif
///////////////////////// queueLL.cpp //////////////////////////
#include "queueLL.h"
#include<iostream>
using namespace std;
class queueLL
{
private:
class node
{
public:
int data;
node* next;
node(int d, node* n = nullptr) : data(d), next(n) {}
};
node* head;
node* tail;
public:
queueLL() : head(nullptr), tail(nullptr) {}
~queueLL()
{
while (!empty())
{
dequeue();
}
}
bool empty()
{
return head == nullptr;
}
void enqueue(int x)
{
node* new_tail = new node(x);
if (empty())
{
head = new_tail;
}
else
{
tail->next = new_tail;
}
tail = new_tail;
}
int dequeue()
{
if (empty())
{
throw std::out_of_range("Queue is empty");
}
int ret = head->data;
node* old_head = head;
head = head->next;
if (head == nullptr)
{
tail = nullptr;
}
delete old_head;
return ret;
}
void decimate()
{
node* current = head;
node* prev = nullptr;
int i = 1;
while (current != nullptr)
{
if (i % 10 == 0)
{
if (prev == nullptr)
{
head = current->next;
}
else
{
prev->next = current->next;
}
node* next = current->next;
delete current;
current = next;
}
else
{
prev = current;
current = current->next;
}
++i;
}
tail = prev;
}
};
//////////////////////////// priorityQueueLL.h /////////////////////////////////
#ifndef PRIORITYQUEUELL_H
#define PRIORITYQUEUELL_H
template <class T>
class priorityQueueLL
{
private:
class node
{
public:
//put what you need here..
}
//add what you wish here
public:
priorityQueueLL()
{}
~priorityQueueLL()
{}
//return true if empty, false if not
bool empty()
{}
//add item
void insert(T x)
{}
//remove and return smallest item
T extractMin()
{}
};
#endif
///////////////////////////// priorityQueueLL.cpp ////////////////////////////////////
#include "priorityQueueLL.h"
#include<iostream>
using namespace std;
template <typename T>
class PriorityQueueLL {
private:
struct Node {
T data;
int priority;
Node* next;
Node(T d, int p) : data(d), priority(p), next(nullptr) {}
};
Node* head;
public:
PriorityQueueLL() : head(nullptr) {}
~PriorityQueueLL() {
while (head) {
Node* temp = head;
head = head->next;
delete temp;
}
}
void push(T data, int priority) {
Node* newNode = new Node(data, priority);
if (!head || priority > head->priority) {
newNode->next = head;
head = newNode;
}
else {
Node* curr = head;
while (curr->next && priority <= curr->next->priority) {
curr = curr->next;
}
newNode->next = curr->next;
curr->next = newNode;
}
}
void pop() {
if (!head) {
throw std::out_of_range("Priority queue is empty");
}
Node* temp = head;
head = head->next;
delete temp;
}
T top() const {
if (!head) {
throw std::out_of_range("Priority queue is empty");
}
return head->data;
}
bool empty() const {
return head == nullptr;
}
};

More Related Content

Similar to I need help with implementing the priority queue data structure with a.docx

Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfalokkesh1
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docxjoyjonna282
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxbradburgess22840
 
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestDeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestAtifkhilji
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfamitbagga0808
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdfAdrianEBJKingr
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdffeelinggift
 
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdfProgramming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdfssuser6254411
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfaassecuritysystem
 
(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdff3apparelsonline
 
IO redirection in C shellPlease implement input output redirect.pdf
IO redirection in C shellPlease implement input  output redirect.pdfIO redirection in C shellPlease implement input  output redirect.pdf
IO redirection in C shellPlease implement input output redirect.pdfforecastfashions
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docxmercysuttle
 
File name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfFile name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfinfomalad
 

Similar to I need help with implementing the priority queue data structure with a.docx (20)

Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docx
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestDeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latest
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
 
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdfProgramming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf(C++) Change the following program so that it uses a dynamic array i.pdf
(C++) Change the following program so that it uses a dynamic array i.pdf
 
IO redirection in C shellPlease implement input output redirect.pdf
IO redirection in C shellPlease implement input  output redirect.pdfIO redirection in C shellPlease implement input  output redirect.pdf
IO redirection in C shellPlease implement input output redirect.pdf
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx
 
File name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfFile name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdf
 
C++ boot camp part 1/2
C++ boot camp part 1/2C++ boot camp part 1/2
C++ boot camp part 1/2
 
C++ Boot Camp Part 1
C++ Boot Camp Part 1C++ Boot Camp Part 1
C++ Boot Camp Part 1
 

More from hendriciraida

In a recent annual report and related Global Responsibiity Report- Sta.docx
In a recent annual report and related Global Responsibiity Report- Sta.docxIn a recent annual report and related Global Responsibiity Report- Sta.docx
In a recent annual report and related Global Responsibiity Report- Sta.docxhendriciraida
 
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docxIn a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docxhendriciraida
 
In a modern economy- who controls the creation of money- Who profits f.docx
In a modern economy- who controls the creation of money- Who profits f.docxIn a modern economy- who controls the creation of money- Who profits f.docx
In a modern economy- who controls the creation of money- Who profits f.docxhendriciraida
 
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docxIn a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docxhendriciraida
 
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docxIn 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docxhendriciraida
 
In 1868- the accidental introduction into the United States of the cot.docx
In 1868- the accidental introduction into the United States of the cot.docxIn 1868- the accidental introduction into the United States of the cot.docx
In 1868- the accidental introduction into the United States of the cot.docxhendriciraida
 
In 1950 the average year of education was 8 years- The standard deviat.docx
In 1950 the average year of education was 8 years- The standard deviat.docxIn 1950 the average year of education was 8 years- The standard deviat.docx
In 1950 the average year of education was 8 years- The standard deviat.docxhendriciraida
 
Important- Python Program- No imports- Use Custom Functions if necessa.docx
Important- Python Program- No imports- Use Custom Functions if necessa.docxImportant- Python Program- No imports- Use Custom Functions if necessa.docx
Important- Python Program- No imports- Use Custom Functions if necessa.docxhendriciraida
 
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docximport java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docxhendriciraida
 
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docxImpact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docxhendriciraida
 
Immune complex is formed when antigen and antibody bind- Formation of.docx
Immune complex is formed when antigen and antibody bind- Formation of.docxImmune complex is formed when antigen and antibody bind- Formation of.docx
Immune complex is formed when antigen and antibody bind- Formation of.docxhendriciraida
 
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docx
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docxImani and Doug were divorced on December 31-2022 - after 10 years of m.docx
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docxhendriciraida
 
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docxIloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docxhendriciraida
 
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docxii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docxhendriciraida
 
If you were living in Galveston at the time- how could you have used y.docx
If you were living in Galveston at the time- how could you have used y.docxIf you were living in Galveston at the time- how could you have used y.docx
If you were living in Galveston at the time- how could you have used y.docxhendriciraida
 
If the share price of Nostos- a New York-based shipping firm- rises fr.docx
If the share price of Nostos- a New York-based shipping firm- rises fr.docxIf the share price of Nostos- a New York-based shipping firm- rises fr.docx
If the share price of Nostos- a New York-based shipping firm- rises fr.docxhendriciraida
 
If the mean annual return for common stocks is 11-0- and the standard.docx
If the mean annual return for common stocks is 11-0- and the standard.docxIf the mean annual return for common stocks is 11-0- and the standard.docx
If the mean annual return for common stocks is 11-0- and the standard.docxhendriciraida
 
If NADH donates a pair of electrons to the mitochondrial electron tran.docx
If NADH donates a pair of electrons to the mitochondrial electron tran.docxIf NADH donates a pair of electrons to the mitochondrial electron tran.docx
If NADH donates a pair of electrons to the mitochondrial electron tran.docxhendriciraida
 
If Molly's pension plan from Retirement Management Services included a.docx
If Molly's pension plan from Retirement Management Services included a.docxIf Molly's pension plan from Retirement Management Services included a.docx
If Molly's pension plan from Retirement Management Services included a.docxhendriciraida
 
If a varlable Y supersedes a variable X- then X must be influencing Y.docx
If a varlable Y supersedes a variable X- then X must be influencing Y.docxIf a varlable Y supersedes a variable X- then X must be influencing Y.docx
If a varlable Y supersedes a variable X- then X must be influencing Y.docxhendriciraida
 

More from hendriciraida (20)

In a recent annual report and related Global Responsibiity Report- Sta.docx
In a recent annual report and related Global Responsibiity Report- Sta.docxIn a recent annual report and related Global Responsibiity Report- Sta.docx
In a recent annual report and related Global Responsibiity Report- Sta.docx
 
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docxIn a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
In a nutshell- Social Darwinism is employed by quasi-scientists and po.docx
 
In a modern economy- who controls the creation of money- Who profits f.docx
In a modern economy- who controls the creation of money- Who profits f.docxIn a modern economy- who controls the creation of money- Who profits f.docx
In a modern economy- who controls the creation of money- Who profits f.docx
 
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docxIn a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.docx
 
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docxIn 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
In 2017 in the economy of Cortania- Consumption was $1500-00- Investme.docx
 
In 1868- the accidental introduction into the United States of the cot.docx
In 1868- the accidental introduction into the United States of the cot.docxIn 1868- the accidental introduction into the United States of the cot.docx
In 1868- the accidental introduction into the United States of the cot.docx
 
In 1950 the average year of education was 8 years- The standard deviat.docx
In 1950 the average year of education was 8 years- The standard deviat.docxIn 1950 the average year of education was 8 years- The standard deviat.docx
In 1950 the average year of education was 8 years- The standard deviat.docx
 
Important- Python Program- No imports- Use Custom Functions if necessa.docx
Important- Python Program- No imports- Use Custom Functions if necessa.docxImportant- Python Program- No imports- Use Custom Functions if necessa.docx
Important- Python Program- No imports- Use Custom Functions if necessa.docx
 
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docximport java-io-IOException- import java-nio-file-Files- import java-ni.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
 
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docxImpact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
Impact on Taxes- You have a marginal tax rate of 22-- You suddenly rea.docx
 
Immune complex is formed when antigen and antibody bind- Formation of.docx
Immune complex is formed when antigen and antibody bind- Formation of.docxImmune complex is formed when antigen and antibody bind- Formation of.docx
Immune complex is formed when antigen and antibody bind- Formation of.docx
 
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docx
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docxImani and Doug were divorced on December 31-2022 - after 10 years of m.docx
Imani and Doug were divorced on December 31-2022 - after 10 years of m.docx
 
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docxIloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
Iloginning rav materiala invantoing siding favimaceriala inventory Dif.docx
 
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docxii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
ii) the 16000$ restumping fee iii- Ihe $2000 tor the new hot water sys.docx
 
If you were living in Galveston at the time- how could you have used y.docx
If you were living in Galveston at the time- how could you have used y.docxIf you were living in Galveston at the time- how could you have used y.docx
If you were living in Galveston at the time- how could you have used y.docx
 
If the share price of Nostos- a New York-based shipping firm- rises fr.docx
If the share price of Nostos- a New York-based shipping firm- rises fr.docxIf the share price of Nostos- a New York-based shipping firm- rises fr.docx
If the share price of Nostos- a New York-based shipping firm- rises fr.docx
 
If the mean annual return for common stocks is 11-0- and the standard.docx
If the mean annual return for common stocks is 11-0- and the standard.docxIf the mean annual return for common stocks is 11-0- and the standard.docx
If the mean annual return for common stocks is 11-0- and the standard.docx
 
If NADH donates a pair of electrons to the mitochondrial electron tran.docx
If NADH donates a pair of electrons to the mitochondrial electron tran.docxIf NADH donates a pair of electrons to the mitochondrial electron tran.docx
If NADH donates a pair of electrons to the mitochondrial electron tran.docx
 
If Molly's pension plan from Retirement Management Services included a.docx
If Molly's pension plan from Retirement Management Services included a.docxIf Molly's pension plan from Retirement Management Services included a.docx
If Molly's pension plan from Retirement Management Services included a.docx
 
If a varlable Y supersedes a variable X- then X must be influencing Y.docx
If a varlable Y supersedes a variable X- then X must be influencing Y.docxIf a varlable Y supersedes a variable X- then X must be influencing Y.docx
If a varlable Y supersedes a variable X- then X must be influencing Y.docx
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

I need help with implementing the priority queue data structure with a.docx

  • 1. I need help with implementing the priority queue data structure with a linked list implementation and with modifying my code with a template. Make sure that the code has the required methods to get the given test code in driver.cpp to work properly. I will provide the main cpp file and what I have so far below. The code is in C++. Add comments to where you modified the code, so I know what you did to change it. Thank you. //////////////////////// driver.cpp ///////////////////////////// #include <iostream> #include <string> #include "stackLL.h" #include "queueLL.h" #include "priorityQueueLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLL stk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout << "Popping: " << stk.pop() << endl; cout << "Popping: " << stk.pop() << endl; stk.push(17); stk.push(19); stk.push(23); while (!stk.empty()) { cout << "Popping: " << stk.pop() << endl; } // output order: 11,2,23,19,17,3,7,13,5 stackLL stkx;
  • 2. stkx.push(5); stkx.push(10); stkx.push(15); stkx.push(20); stkx.push(25); stkx.push(30); stkx.insertAt(-100, 3); stkx.insertAt(-200, 7); stkx.insertAt(-300, 0); //output order: -300,30,25,20,-100,15,10,5,-200 while (!stkx.empty()) cout << "Popping: " << stkx.pop() << endl; /////////////////////////////////////// //////////Test code for queue /////////// queueLL Q; Q.enqueue(1); Q.enqueue(2); Q.enqueue(3); cout << "Dequeuing: " << Q.dequeue() << endl; //1 cout << "Dequeuing: " << Q.dequeue() << endl; //2 Q.enqueue(4); Q.enqueue(5); //3 4 5 while (!Q.empty()) { cout << "Dequeuing: " << Q.dequeue() << endl; } ///////////////////////////////////////// //////////Test code for priority queue///// priorityQueueLL<int> pQueue; const int SIZE = 20; //insert a bunch of random numbers for (int i = 0; i < SIZE; i++)
  • 3. { pQueue.insert(rand()); } //pull them back out.. //They must come out in order from smallest to largest while (!pQueue.empty()) { cout << pQueue.extractMin() << endl; } priorityQueueLL<string> pqs; pqs.insert("whale"); pqs.insert("snake"); pqs.insert("buffalo"); pqs.insert("elmo"); pqs.insert("fire"); pqs.insert("waffle"); //buffalo elmo fire snake waffle whale while (!pqs.empty()) { cout << pqs.extractMin() << endl; } /////////////////////////////////////////// //1) Template your queue class //2) Add a decimate method to your queue class queueLL<int> qx; for (int i = 1; i <= 100; i++) qx.enqueue(i); //Eliminate every 10th item from list //https://en.wikipedia.org/wiki/Decimation_(punishment) qx.decimate(); //1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 21 22... 98 99 while (!qx.empty()) cout << qx.dequeue() << endl; queueLL<string> qy; qy.enqueue("sparticus");
  • 4. qy.enqueue("maximus"); qy.enqueue("killicus"); qy.enqueue("awesomeicus"); qy.enqueue("gannicus"); qy.enqueue("varro"); qy.enqueue("oenomous"); qy.enqueue("slayicus"); qy.enqueue("bladeicus"); qy.enqueue("ted"); qy.enqueue("smashicus"); qy.enqueue("mallicus"); qy.enqueue("wussicus"); qy.enqueue("wimpicus"); qy.enqueue("crixus"); qy.decimate(); //Everyone but Ted. while (!qy.empty()) cout << qy.dequeue() << endl; return 0; } //////////////////////// queueLL.h /////////////////////////// #ifndef QUEUELL_H #define QUEUELL_H class queueLL { private: //put what you need here... public: queueLL() {} ~queueLL() {} //return true if empty, false if not bool empty() {}
  • 5. //add item to back of queue void enqueue(int x) {} //remove and return first item from queue int dequeue() {} //For the final part of the test program, template this class //and add a decimate method. }; #endif ///////////////////////// queueLL.cpp ////////////////////////// #include "queueLL.h" #include<iostream> using namespace std; class queueLL { private: class node { public: int data; node* next; node(int d, node* n = nullptr) : data(d), next(n) {} }; node* head; node* tail; public: queueLL() : head(nullptr), tail(nullptr) {} ~queueLL() { while (!empty()) { dequeue(); } } bool empty() {
  • 6. return head == nullptr; } void enqueue(int x) { node* new_tail = new node(x); if (empty()) { head = new_tail; } else { tail->next = new_tail; } tail = new_tail; } int dequeue() { if (empty()) { throw std::out_of_range("Queue is empty"); } int ret = head->data; node* old_head = head; head = head->next; if (head == nullptr) { tail = nullptr; } delete old_head; return ret; } void decimate() { node* current = head; node* prev = nullptr; int i = 1; while (current != nullptr) { if (i % 10 == 0) { if (prev == nullptr) { head = current->next;
  • 7. } else { prev->next = current->next; } node* next = current->next; delete current; current = next; } else { prev = current; current = current->next; } ++i; } tail = prev; } }; //////////////////////////// priorityQueueLL.h ///////////////////////////////// #ifndef PRIORITYQUEUELL_H #define PRIORITYQUEUELL_H template <class T> class priorityQueueLL { private: class node { public: //put what you need here.. } //add what you wish here public: priorityQueueLL() {} ~priorityQueueLL() {}
  • 8. //return true if empty, false if not bool empty() {} //add item void insert(T x) {} //remove and return smallest item T extractMin() {} }; #endif ///////////////////////////// priorityQueueLL.cpp //////////////////////////////////// #include "priorityQueueLL.h" #include<iostream> using namespace std; template <typename T> class PriorityQueueLL { private: struct Node { T data; int priority; Node* next; Node(T d, int p) : data(d), priority(p), next(nullptr) {} }; Node* head; public: PriorityQueueLL() : head(nullptr) {} ~PriorityQueueLL() { while (head) { Node* temp = head; head = head->next; delete temp; } } void push(T data, int priority) { Node* newNode = new Node(data, priority); if (!head || priority > head->priority) { newNode->next = head;
  • 9. head = newNode; } else { Node* curr = head; while (curr->next && priority <= curr->next->priority) { curr = curr->next; } newNode->next = curr->next; curr->next = newNode; } } void pop() { if (!head) { throw std::out_of_range("Priority queue is empty"); } Node* temp = head; head = head->next; delete temp; } T top() const { if (!head) { throw std::out_of_range("Priority queue is empty"); } return head->data; } bool empty() const { return head == nullptr; } };