SlideShare a Scribd company logo
Implement a priority queue using a doublyLinked.cpp where the node with the highest
priority (key) is the right-most node.
The remove (de-queue) operation returns the node with the highest priority (key).
If displayForward() displays List (first-->last) : 10 30 40 55
remove() would return the node with key 55.
please only code in c++ not anything else. keep it simple and thank you!!
Demonstrate by inserting keys at random, displayForward(), call remove then
displayForward() again.
int main()
{
DoublyLinkedList pqList;
pqList.priorityInsert(50);
pqList.priorityInsert(40);
pqList.priorityInsert(30);
pqList.priorityInsert(20);
pqList.priorityInsert(10);
cout<<"-------------- PriorityQueue -------------"<<endl;
pqList.displayForward();
cout<<"calling priorityRemove()"<<endl;
double key = pqList.priorityRemove();
cout<<"Removed node with key "<<key<<endl;
pqList.displayForward();
key = pqList.priorityRemove();
cout<<"Removed node with key "<<key<<endl;
pqList.displayForward();
return 0;
}
Sample output"
-------------- PriorityQueue -------------
List (first-->last): 10 20 30 40 50
calling priorityRemove()
Removed node with key 50
List (first-->last): 10 20 30 40
Removed node with key 40
List (first-->last): 10 20 30
I may change numbers when grading.
doublyLinked.cpp
//doublyLinked.cpp
//demonstrates doubly-linked list
#include <iostream>
using namespace std;
////////////////////////////////////////////////////////////////
class Link {
public:
double dData; //data item
Link * pNext; //next link in list
Link * pPrevious; //previous link in list
public:
//-------------------------------------------------------------
Link(double dd): //constructor
dData(dd), pNext(NULL), pPrevious(NULL) {}
//-------------------------------------------------------------
void displayLink() //display this link
{
cout << dData << " ";
}
//-------------------------------------------------------------
}; //end class Link
////////////////////////////////////////////////////////////////
class DoublyLinkedList {
private:
Link * pFirst; //pointer to first item
Link * pLast; //pointer to last item
public:
//-------------------------------------------------------------
DoublyLinkedList(): //constructor
pFirst(NULL), pLast(NULL) {}
//-------------------------------------------------------------
~DoublyLinkedList() //destructor (deletes links)
{
Link * pCurrent = pFirst; //start at beginning of list
while (pCurrent != NULL) //until end of list,
{
Link * pOldCur = pCurrent; //save current link
pCurrent = pCurrent -> pNext; //move to next link
delete pOldCur; //delete old current
}
}
//-------------------------------------------------------------
bool isEmpty() //true if no links
{
return pFirst == NULL;
}
//-------------------------------------------------------------
void insertFirst(double dd) //insert at front of list
{
Link * pNewLink = new Link(dd); //make new link
if (isEmpty()) //if empty list,
pLast = pNewLink; //newLink <-- last
else
pFirst -> pPrevious = pNewLink; //newLink <-- old first
pNewLink -> pNext = pFirst; //newLink --> old first
pFirst = pNewLink; //first --> newLink
}
//-------------------------------------------------------------
void insertLast(double dd) //insert at end of list
{
Link * pNewLink = new Link(dd); //make new link
if (isEmpty()) //if empty list,
pFirst = pNewLink; //first --> newLink
else {
pLast -> pNext = pNewLink; //old last --> newLink
pNewLink -> pPrevious = pLast; //old last <-- newLink
}
pLast = pNewLink; //newLink <-- last
}
//-------------------------------------------------------------
void removeFirst() //remove first link
{ //(assumes non-empty list)
Link * pTemp = pFirst;
if (pFirst -> pNext == NULL) //if only one item
pLast = NULL; //null <-- last
else
pFirst -> pNext -> pPrevious = NULL; //null <-- old next
pFirst = pFirst -> pNext; //first --> old next
delete pTemp; //delete old first
}
//-------------------------------------------------------------
void removeLast() //remove last link
{ //(assumes non-empty list)
Link * pTemp = pLast;
if (pFirst -> pNext == NULL) //if only one item
pFirst = NULL; //first --> null
else
pLast -> pPrevious -> pNext = NULL; //old previous --> null
pLast = pLast -> pPrevious; //old previous <-- last
delete pTemp; //delete old last
}
//-------------------------------------------------------------
//insert dd just after key
bool insertAfter(double key, double dd) { //(assumes non-empty list)
Link * pCurrent = pFirst; //start at beginning
while (pCurrent -> dData != key) //until match is found,
{
pCurrent = pCurrent -> pNext; //move to next link
if (pCurrent == NULL)
return false; //didnt find it
}
Link * pNewLink = new Link(dd); //make new link
if (pCurrent == pLast) //if last link,
{
pNewLink -> pNext = NULL; //newLink --> null
pLast = pNewLink; //newLink <-- last
} else //not last link,
{ //newLink --> old next
pNewLink -> pNext = pCurrent -> pNext;
//newLink <-- old next
pCurrent -> pNext -> pPrevious = pNewLink;
}
pNewLink -> pPrevious = pCurrent; //old current <-- newLink
pCurrent -> pNext = pNewLink; //old current --> newLink
return true; //found it, did insertion
}
//-------------------------------------------------------------
bool removeKey(double key) //remove item w/ given key
{ //(assumes non-empty list)
Link * pCurrent = pFirst; //start at beginning
while (pCurrent -> dData != key) //until match is found,
{
pCurrent = pCurrent -> pNext; //move to next link
if (pCurrent == NULL)
return false; //didnt find it
}
if (pCurrent == pFirst) //found it; first item?
pFirst = pCurrent -> pNext; //first --> old next
else //not first
//old previous --> old next
pCurrent -> pPrevious -> pNext = pCurrent -> pNext;
if (pCurrent == pLast) //last item?
pLast = pCurrent -> pPrevious; //old previous <-- last
else //not last
//old previous <-- old next
pCurrent -> pNext -> pPrevious = pCurrent -> pPrevious;
delete pCurrent; //delete item
return true; //successful deletion
}
//-------------------------------------------------------------
void displayForward() {
cout << "List (first-->last): ";
Link * pCurrent = pFirst; //start at beginning
while (pCurrent != NULL) //until end of list,
{
pCurrent -> displayLink(); //display data
pCurrent = pCurrent -> pNext; //move to next link
}
cout << endl;
}
//-------------------------------------------------------------
void displayBackward() {
cout << "List (last-->first): ";
Link * pCurrent = pLast; //start at end
while (pCurrent != NULL) //until start of list,
{
pCurrent -> displayLink(); //display data
pCurrent = pCurrent -> pPrevious; //go to previous link
}
cout << endl;
}
//-------------------------------------------------------------
}; //end class DoublyLinkedList
////////////////////////////////////////////////////////////////
int main() {
DoublyLinkedList theList; //make a new list
theList.insertFirst(22); //insert at front
theList.insertFirst(44);
theList.insertFirst(66);
theList.insertLast(11); //insert at rear
theList.insertLast(33);
theList.insertLast(55);
theList.displayForward(); //display list forward
theList.displayBackward(); //display list backward
cout << "Deleting first, last, and 11" << endl;
theList.removeFirst(); //remove first item
theList.removeLast(); //remove last item
theList.removeKey(11); //remove item with key 11
theList.displayForward(); //display list forward
cout << "Inserting 77 after 22, and 88 after 33" << endl;
theList.insertAfter(22, 77); //insert 77 after 22
theList.insertAfter(33, 88); //insert 88 after 33
theList.displayForward(); //display list forward
return 0;
} //end main()
Program 5 to test the code and call it.
#include "doublyLinked2.cpp"
#include <iostream>
using namespace std;
int main() {
DoublyLinkedList pqList;
pqList.priorityInsert(50);
pqList.displayForward();
pqList.priorityInsert(80);
pqList.displayForward();
pqList.priorityInsert(40);
pqList.displayForward();
pqList.priorityInsert(30);
pqList.priorityInsert(20);
pqList.priorityInsert(10);
pqList.priorityInsert(70);
pqList.priorityInsert(24);
cout<<"-------------- PriorityQueue -------------"<<endl;
pqList.displayForward();
cout<<"ncalling priorityRemove()"<<endl;
double key = pqList.priorityRemove();
cout<<"Removed node with key "<<key<<endl;
pqList.displayForward();
key = pqList.priorityRemove();
cout<<"Removed node with key "<<key<<endl;
pqList.displayForward();
cout<<"Display backward:"<<endl;
pqList.displayBackward();
return 0;
}

More Related Content

Similar to Implement a priority queue using a doublyLinked-cpp where the node wit.pdf

Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
wkyra78
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
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
alokkesh1
 
I need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docxI need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docx
hendriciraida
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
Anaya Zafar
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
ZarghamullahShah
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
hadpadrrajeshh
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
 
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docxLISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
SHIVA101531
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
Sarmad Baloch
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
sudhirchourasia86
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
shanki7
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
arkleatheray
 
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
infomalad
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
brijmote
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 

Similar to Implement a priority queue using a doublyLinked-cpp where the node wit.pdf (20)

Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
 
Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
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
 
I need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docxI need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docx
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docxLISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
 
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
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 

More from BlakeY8lBucklandh

IN KOTLIN PLZ Define a public class named Stepper with a single instan.pdf
IN KOTLIN PLZ Define a public class named Stepper with a single instan.pdfIN KOTLIN PLZ Define a public class named Stepper with a single instan.pdf
IN KOTLIN PLZ Define a public class named Stepper with a single instan.pdf
BlakeY8lBucklandh
 
In less than two pages- I want you to examine the pattern of human pop.pdf
In less than two pages- I want you to examine the pattern of human pop.pdfIn less than two pages- I want you to examine the pattern of human pop.pdf
In less than two pages- I want you to examine the pattern of human pop.pdf
BlakeY8lBucklandh
 
in HTML 2- Write an html file that has two images side by side- The i.pdf
in HTML  2- Write an html file that has two images side by side- The i.pdfin HTML  2- Write an html file that has two images side by side- The i.pdf
in HTML 2- Write an html file that has two images side by side- The i.pdf
BlakeY8lBucklandh
 
In Germany the corporate board is--- A-Legally charged with representi.pdf
In Germany the corporate board is--- A-Legally charged with representi.pdfIn Germany the corporate board is--- A-Legally charged with representi.pdf
In Germany the corporate board is--- A-Legally charged with representi.pdf
BlakeY8lBucklandh
 
In Excel- you are allowed to put other functions inside an -F( ) state.pdf
In Excel- you are allowed to put other functions inside an -F( ) state.pdfIn Excel- you are allowed to put other functions inside an -F( ) state.pdf
In Excel- you are allowed to put other functions inside an -F( ) state.pdf
BlakeY8lBucklandh
 
In examining those two profiles from Mount Saint Helens- which one has.pdf
In examining those two profiles from Mount Saint Helens- which one has.pdfIn examining those two profiles from Mount Saint Helens- which one has.pdf
In examining those two profiles from Mount Saint Helens- which one has.pdf
BlakeY8lBucklandh
 
In December 1991- the United Nations (UN) warned that wheat would be s.pdf
In December 1991- the United Nations (UN) warned that wheat would be s.pdfIn December 1991- the United Nations (UN) warned that wheat would be s.pdf
In December 1991- the United Nations (UN) warned that wheat would be s.pdf
BlakeY8lBucklandh
 
In carrying out their engagements- which financial advisor would NOT b.pdf
In carrying out their engagements- which financial advisor would NOT b.pdfIn carrying out their engagements- which financial advisor would NOT b.pdf
In carrying out their engagements- which financial advisor would NOT b.pdf
BlakeY8lBucklandh
 
In astronomy- it is important to look for trends in your data- Based o.pdf
In astronomy- it is important to look for trends in your data- Based o.pdfIn astronomy- it is important to look for trends in your data- Based o.pdf
In astronomy- it is important to look for trends in your data- Based o.pdf
BlakeY8lBucklandh
 
In a horizontal structure- __________ deal directly with the organizat.pdf
In a horizontal structure- __________ deal directly with the organizat.pdfIn a horizontal structure- __________ deal directly with the organizat.pdf
In a horizontal structure- __________ deal directly with the organizat.pdf
BlakeY8lBucklandh
 
In a certain residential area 50- of the residents subscribe to the mo.pdf
In a certain residential area 50- of the residents subscribe to the mo.pdfIn a certain residential area 50- of the residents subscribe to the mo.pdf
In a certain residential area 50- of the residents subscribe to the mo.pdf
BlakeY8lBucklandh
 
In a binary tree class- implement a Python method _find(p- _Node- key-.pdf
In a binary tree class- implement a Python method _find(p- _Node- key-.pdfIn a binary tree class- implement a Python method _find(p- _Node- key-.pdf
In a binary tree class- implement a Python method _find(p- _Node- key-.pdf
BlakeY8lBucklandh
 
Implementing a Singly Linked List The purpose of the lab is to help gi.pdf
Implementing a Singly Linked List The purpose of the lab is to help gi.pdfImplementing a Singly Linked List The purpose of the lab is to help gi.pdf
Implementing a Singly Linked List The purpose of the lab is to help gi.pdf
BlakeY8lBucklandh
 
Implement the following classes in the UML- 1- Iist class includes- co.pdf
Implement the following classes in the UML- 1- Iist class includes- co.pdfImplement the following classes in the UML- 1- Iist class includes- co.pdf
Implement the following classes in the UML- 1- Iist class includes- co.pdf
BlakeY8lBucklandh
 
In 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdf
In 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdfIn 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdf
In 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdf
BlakeY8lBucklandh
 
In 2012- Facebook Inc- filed with the SEC a registration statement und.pdf
In 2012- Facebook Inc- filed with the SEC a registration statement und.pdfIn 2012- Facebook Inc- filed with the SEC a registration statement und.pdf
In 2012- Facebook Inc- filed with the SEC a registration statement und.pdf
BlakeY8lBucklandh
 
Ildentity the tollowing fuctors affecting kpecies distribution that ar.pdf
Ildentity the tollowing fuctors affecting kpecies distribution that ar.pdfIldentity the tollowing fuctors affecting kpecies distribution that ar.pdf
Ildentity the tollowing fuctors affecting kpecies distribution that ar.pdf
BlakeY8lBucklandh
 
If X is normally distributed with a mean of 10 and a standard deviatio (1).pdf
If X is normally distributed with a mean of 10 and a standard deviatio (1).pdfIf X is normally distributed with a mean of 10 and a standard deviatio (1).pdf
If X is normally distributed with a mean of 10 and a standard deviatio (1).pdf
BlakeY8lBucklandh
 
If ZN(0-1)- compute P(Z2-3)-.pdf
If ZN(0-1)- compute P(Z2-3)-.pdfIf ZN(0-1)- compute P(Z2-3)-.pdf
If ZN(0-1)- compute P(Z2-3)-.pdf
BlakeY8lBucklandh
 
illings is exceeding the design specification- Use Table 11-1- interpr.pdf
illings is exceeding the design specification- Use Table 11-1- interpr.pdfillings is exceeding the design specification- Use Table 11-1- interpr.pdf
illings is exceeding the design specification- Use Table 11-1- interpr.pdf
BlakeY8lBucklandh
 

More from BlakeY8lBucklandh (20)

IN KOTLIN PLZ Define a public class named Stepper with a single instan.pdf
IN KOTLIN PLZ Define a public class named Stepper with a single instan.pdfIN KOTLIN PLZ Define a public class named Stepper with a single instan.pdf
IN KOTLIN PLZ Define a public class named Stepper with a single instan.pdf
 
In less than two pages- I want you to examine the pattern of human pop.pdf
In less than two pages- I want you to examine the pattern of human pop.pdfIn less than two pages- I want you to examine the pattern of human pop.pdf
In less than two pages- I want you to examine the pattern of human pop.pdf
 
in HTML 2- Write an html file that has two images side by side- The i.pdf
in HTML  2- Write an html file that has two images side by side- The i.pdfin HTML  2- Write an html file that has two images side by side- The i.pdf
in HTML 2- Write an html file that has two images side by side- The i.pdf
 
In Germany the corporate board is--- A-Legally charged with representi.pdf
In Germany the corporate board is--- A-Legally charged with representi.pdfIn Germany the corporate board is--- A-Legally charged with representi.pdf
In Germany the corporate board is--- A-Legally charged with representi.pdf
 
In Excel- you are allowed to put other functions inside an -F( ) state.pdf
In Excel- you are allowed to put other functions inside an -F( ) state.pdfIn Excel- you are allowed to put other functions inside an -F( ) state.pdf
In Excel- you are allowed to put other functions inside an -F( ) state.pdf
 
In examining those two profiles from Mount Saint Helens- which one has.pdf
In examining those two profiles from Mount Saint Helens- which one has.pdfIn examining those two profiles from Mount Saint Helens- which one has.pdf
In examining those two profiles from Mount Saint Helens- which one has.pdf
 
In December 1991- the United Nations (UN) warned that wheat would be s.pdf
In December 1991- the United Nations (UN) warned that wheat would be s.pdfIn December 1991- the United Nations (UN) warned that wheat would be s.pdf
In December 1991- the United Nations (UN) warned that wheat would be s.pdf
 
In carrying out their engagements- which financial advisor would NOT b.pdf
In carrying out their engagements- which financial advisor would NOT b.pdfIn carrying out their engagements- which financial advisor would NOT b.pdf
In carrying out their engagements- which financial advisor would NOT b.pdf
 
In astronomy- it is important to look for trends in your data- Based o.pdf
In astronomy- it is important to look for trends in your data- Based o.pdfIn astronomy- it is important to look for trends in your data- Based o.pdf
In astronomy- it is important to look for trends in your data- Based o.pdf
 
In a horizontal structure- __________ deal directly with the organizat.pdf
In a horizontal structure- __________ deal directly with the organizat.pdfIn a horizontal structure- __________ deal directly with the organizat.pdf
In a horizontal structure- __________ deal directly with the organizat.pdf
 
In a certain residential area 50- of the residents subscribe to the mo.pdf
In a certain residential area 50- of the residents subscribe to the mo.pdfIn a certain residential area 50- of the residents subscribe to the mo.pdf
In a certain residential area 50- of the residents subscribe to the mo.pdf
 
In a binary tree class- implement a Python method _find(p- _Node- key-.pdf
In a binary tree class- implement a Python method _find(p- _Node- key-.pdfIn a binary tree class- implement a Python method _find(p- _Node- key-.pdf
In a binary tree class- implement a Python method _find(p- _Node- key-.pdf
 
Implementing a Singly Linked List The purpose of the lab is to help gi.pdf
Implementing a Singly Linked List The purpose of the lab is to help gi.pdfImplementing a Singly Linked List The purpose of the lab is to help gi.pdf
Implementing a Singly Linked List The purpose of the lab is to help gi.pdf
 
Implement the following classes in the UML- 1- Iist class includes- co.pdf
Implement the following classes in the UML- 1- Iist class includes- co.pdfImplement the following classes in the UML- 1- Iist class includes- co.pdf
Implement the following classes in the UML- 1- Iist class includes- co.pdf
 
In 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdf
In 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdfIn 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdf
In 2017 Marcus Hutchins (Malware Tech Blog) was arrested as he was att.pdf
 
In 2012- Facebook Inc- filed with the SEC a registration statement und.pdf
In 2012- Facebook Inc- filed with the SEC a registration statement und.pdfIn 2012- Facebook Inc- filed with the SEC a registration statement und.pdf
In 2012- Facebook Inc- filed with the SEC a registration statement und.pdf
 
Ildentity the tollowing fuctors affecting kpecies distribution that ar.pdf
Ildentity the tollowing fuctors affecting kpecies distribution that ar.pdfIldentity the tollowing fuctors affecting kpecies distribution that ar.pdf
Ildentity the tollowing fuctors affecting kpecies distribution that ar.pdf
 
If X is normally distributed with a mean of 10 and a standard deviatio (1).pdf
If X is normally distributed with a mean of 10 and a standard deviatio (1).pdfIf X is normally distributed with a mean of 10 and a standard deviatio (1).pdf
If X is normally distributed with a mean of 10 and a standard deviatio (1).pdf
 
If ZN(0-1)- compute P(Z2-3)-.pdf
If ZN(0-1)- compute P(Z2-3)-.pdfIf ZN(0-1)- compute P(Z2-3)-.pdf
If ZN(0-1)- compute P(Z2-3)-.pdf
 
illings is exceeding the design specification- Use Table 11-1- interpr.pdf
illings is exceeding the design specification- Use Table 11-1- interpr.pdfillings is exceeding the design specification- Use Table 11-1- interpr.pdf
illings is exceeding the design specification- Use Table 11-1- interpr.pdf
 

Recently uploaded

DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 

Implement a priority queue using a doublyLinked-cpp where the node wit.pdf

  • 1. Implement a priority queue using a doublyLinked.cpp where the node with the highest priority (key) is the right-most node. The remove (de-queue) operation returns the node with the highest priority (key). If displayForward() displays List (first-->last) : 10 30 40 55 remove() would return the node with key 55. please only code in c++ not anything else. keep it simple and thank you!! Demonstrate by inserting keys at random, displayForward(), call remove then displayForward() again. int main() { DoublyLinkedList pqList; pqList.priorityInsert(50); pqList.priorityInsert(40); pqList.priorityInsert(30); pqList.priorityInsert(20); pqList.priorityInsert(10); cout<<"-------------- PriorityQueue -------------"<<endl; pqList.displayForward(); cout<<"calling priorityRemove()"<<endl; double key = pqList.priorityRemove(); cout<<"Removed node with key "<<key<<endl; pqList.displayForward(); key = pqList.priorityRemove(); cout<<"Removed node with key "<<key<<endl; pqList.displayForward(); return 0; } Sample output" -------------- PriorityQueue ------------- List (first-->last): 10 20 30 40 50 calling priorityRemove() Removed node with key 50 List (first-->last): 10 20 30 40 Removed node with key 40 List (first-->last): 10 20 30 I may change numbers when grading. doublyLinked.cpp //doublyLinked.cpp //demonstrates doubly-linked list #include <iostream>
  • 2. using namespace std; //////////////////////////////////////////////////////////////// class Link { public: double dData; //data item Link * pNext; //next link in list Link * pPrevious; //previous link in list public: //------------------------------------------------------------- Link(double dd): //constructor dData(dd), pNext(NULL), pPrevious(NULL) {} //------------------------------------------------------------- void displayLink() //display this link { cout << dData << " "; } //------------------------------------------------------------- }; //end class Link //////////////////////////////////////////////////////////////// class DoublyLinkedList { private: Link * pFirst; //pointer to first item Link * pLast; //pointer to last item public: //------------------------------------------------------------- DoublyLinkedList(): //constructor pFirst(NULL), pLast(NULL) {} //------------------------------------------------------------- ~DoublyLinkedList() //destructor (deletes links) { Link * pCurrent = pFirst; //start at beginning of list while (pCurrent != NULL) //until end of list, { Link * pOldCur = pCurrent; //save current link pCurrent = pCurrent -> pNext; //move to next link delete pOldCur; //delete old current } } //------------------------------------------------------------- bool isEmpty() //true if no links { return pFirst == NULL;
  • 3. } //------------------------------------------------------------- void insertFirst(double dd) //insert at front of list { Link * pNewLink = new Link(dd); //make new link if (isEmpty()) //if empty list, pLast = pNewLink; //newLink <-- last else pFirst -> pPrevious = pNewLink; //newLink <-- old first pNewLink -> pNext = pFirst; //newLink --> old first pFirst = pNewLink; //first --> newLink } //------------------------------------------------------------- void insertLast(double dd) //insert at end of list { Link * pNewLink = new Link(dd); //make new link if (isEmpty()) //if empty list, pFirst = pNewLink; //first --> newLink else { pLast -> pNext = pNewLink; //old last --> newLink pNewLink -> pPrevious = pLast; //old last <-- newLink } pLast = pNewLink; //newLink <-- last } //------------------------------------------------------------- void removeFirst() //remove first link { //(assumes non-empty list) Link * pTemp = pFirst; if (pFirst -> pNext == NULL) //if only one item pLast = NULL; //null <-- last else pFirst -> pNext -> pPrevious = NULL; //null <-- old next pFirst = pFirst -> pNext; //first --> old next delete pTemp; //delete old first } //-------------------------------------------------------------
  • 4. void removeLast() //remove last link { //(assumes non-empty list) Link * pTemp = pLast; if (pFirst -> pNext == NULL) //if only one item pFirst = NULL; //first --> null else pLast -> pPrevious -> pNext = NULL; //old previous --> null pLast = pLast -> pPrevious; //old previous <-- last delete pTemp; //delete old last } //------------------------------------------------------------- //insert dd just after key bool insertAfter(double key, double dd) { //(assumes non-empty list) Link * pCurrent = pFirst; //start at beginning while (pCurrent -> dData != key) //until match is found, { pCurrent = pCurrent -> pNext; //move to next link if (pCurrent == NULL) return false; //didnt find it } Link * pNewLink = new Link(dd); //make new link if (pCurrent == pLast) //if last link, { pNewLink -> pNext = NULL; //newLink --> null pLast = pNewLink; //newLink <-- last } else //not last link, { //newLink --> old next pNewLink -> pNext = pCurrent -> pNext; //newLink <-- old next pCurrent -> pNext -> pPrevious = pNewLink; } pNewLink -> pPrevious = pCurrent; //old current <-- newLink pCurrent -> pNext = pNewLink; //old current --> newLink return true; //found it, did insertion } //------------------------------------------------------------- bool removeKey(double key) //remove item w/ given key { //(assumes non-empty list)
  • 5. Link * pCurrent = pFirst; //start at beginning while (pCurrent -> dData != key) //until match is found, { pCurrent = pCurrent -> pNext; //move to next link if (pCurrent == NULL) return false; //didnt find it } if (pCurrent == pFirst) //found it; first item? pFirst = pCurrent -> pNext; //first --> old next else //not first //old previous --> old next pCurrent -> pPrevious -> pNext = pCurrent -> pNext; if (pCurrent == pLast) //last item? pLast = pCurrent -> pPrevious; //old previous <-- last else //not last //old previous <-- old next pCurrent -> pNext -> pPrevious = pCurrent -> pPrevious; delete pCurrent; //delete item return true; //successful deletion } //------------------------------------------------------------- void displayForward() { cout << "List (first-->last): "; Link * pCurrent = pFirst; //start at beginning while (pCurrent != NULL) //until end of list, { pCurrent -> displayLink(); //display data pCurrent = pCurrent -> pNext; //move to next link } cout << endl; } //------------------------------------------------------------- void displayBackward() { cout << "List (last-->first): "; Link * pCurrent = pLast; //start at end while (pCurrent != NULL) //until start of list, { pCurrent -> displayLink(); //display data pCurrent = pCurrent -> pPrevious; //go to previous link
  • 6. } cout << endl; } //------------------------------------------------------------- }; //end class DoublyLinkedList //////////////////////////////////////////////////////////////// int main() { DoublyLinkedList theList; //make a new list theList.insertFirst(22); //insert at front theList.insertFirst(44); theList.insertFirst(66); theList.insertLast(11); //insert at rear theList.insertLast(33); theList.insertLast(55); theList.displayForward(); //display list forward theList.displayBackward(); //display list backward cout << "Deleting first, last, and 11" << endl; theList.removeFirst(); //remove first item theList.removeLast(); //remove last item theList.removeKey(11); //remove item with key 11 theList.displayForward(); //display list forward cout << "Inserting 77 after 22, and 88 after 33" << endl; theList.insertAfter(22, 77); //insert 77 after 22 theList.insertAfter(33, 88); //insert 88 after 33 theList.displayForward(); //display list forward return 0; } //end main() Program 5 to test the code and call it. #include "doublyLinked2.cpp" #include <iostream> using namespace std; int main() { DoublyLinkedList pqList;
  • 7. pqList.priorityInsert(50); pqList.displayForward(); pqList.priorityInsert(80); pqList.displayForward(); pqList.priorityInsert(40); pqList.displayForward(); pqList.priorityInsert(30); pqList.priorityInsert(20); pqList.priorityInsert(10); pqList.priorityInsert(70); pqList.priorityInsert(24); cout<<"-------------- PriorityQueue -------------"<<endl; pqList.displayForward(); cout<<"ncalling priorityRemove()"<<endl; double key = pqList.priorityRemove(); cout<<"Removed node with key "<<key<<endl; pqList.displayForward(); key = pqList.priorityRemove(); cout<<"Removed node with key "<<key<<endl; pqList.displayForward(); cout<<"Display backward:"<<endl; pqList.displayBackward(); return 0; }