#include #include #include using namespace std; // Krone class class Krone { private: int wholeValue; int fractionalValue; public: Krone() {} Krone(int whole, int fraction) : wholeValue(whole), fractionalValue(fraction) {} int getWhole() const { return wholeValue; } int getFraction() const { return fractionalValue; } bool operator<(const Krone& other) const { if (wholeValue < other.wholeValue) { return true; } else if (wholeValue == other.wholeValue) { return fractionalValue < other.fractionalValue; } else { return false; } } friend ostream& operator<<(ostream& out, const Krone& krone) { out << "Kr " << krone.wholeValue << "." << krone.fractionalValue; return out; } }; // BST Node class class BSTNode { private: Krone data; BSTNode* left; BSTNode* right; public: BSTNode() {} BSTNode(const Krone& krone) : data(krone), left(nullptr), right(nullptr) {} Krone getData() const { return data; } BSTNode* getLeft() const { return left; } BSTNode* getRight() const { return right; } void setData(const Krone& krone) { data = krone; } void setLeft(BSTNode* node) { left = node; } void setRight(BSTNode* node) { right = node; } }; // BST class class BST { protected: BSTNode* root; public: BST() : root(nullptr) {} BSTNode* getRoot() const { return root; } bool isEmpty() const { return root == nullptr; } int countNodes(BSTNode* node) const { if (node == nullptr) { return 0; } else { return 1 + countNodes(node->getLeft()) + countNodes(node->getRight()); } }
can you fix
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
// Krone class
class Krone {
private:
int wholeValue;
int fractionalValue;
public:
Krone() {}
Krone(int whole, int fraction) : wholeValue(whole), fractionalValue(fraction) {}
int getWhole() const { return wholeValue; }
int getFraction() const { return fractionalValue; }
bool operator<(const Krone& other) const {
if (wholeValue < other.wholeValue) {
return true;
}
else if (wholeValue == other.wholeValue) {
return fractionalValue < other.fractionalValue;
}
else {
return false;
}
}
friend ostream& operator<<(ostream& out, const Krone& krone) {
out << "Kr " << krone.wholeValue << "." << krone.fractionalValue;
return out;
}
};
// BST Node class
class BSTNode {
private:
Krone data;
BSTNode* left;
BSTNode* right;
public:
BSTNode() {}
BSTNode(const Krone& krone) : data(krone), left(nullptr), right(nullptr) {}
Krone getData() const { return data; }
BSTNode* getLeft() const { return left; }
BSTNode* getRight() const { return right; }
void setData(const Krone& krone) { data = krone; }
void setLeft(BSTNode* node) { left = node; }
void setRight(BSTNode* node) { right = node; }
};
// BST class
class BST {
protected:
BSTNode* root;
public:
BST() : root(nullptr) {}
BSTNode* getRoot() const { return root; }
bool isEmpty() const { return root == nullptr; }
int countNodes(BSTNode* node) const {
if (node == nullptr) {
return 0;
}
else {
return 1 + countNodes(node->getLeft()) + countNodes(node->getRight());
}
}
void empty(BSTNode* node) {
if (node != nullptr) {
empty(node->getLeft());
empty(node->getRight());
delete node;
}
}
void insertNode(const Krone& krone) {
BSTNode* node = new BSTNode(krone);
if (isEmpty()) {
root = node;
}
else {
BSTNode* currNode = root;
while (true) {
if (krone < currNode->getData()) {
if (currNode->getLeft() == nullptr) {
currNode->setLeft(node);
break;
}
else {
currNode = currNode->getLeft();
}
}
else {
if (currNode->getRight() == nullptr) {
currNode->setRight(node);
break;
}
else {
currNode = currNode->getRight();
}
}
}
}
}
BSTNode* searchNode(const Krone& krone) const {
BSTNode* currNode = root;
while (currNode != nullptr) {
if (krone < currNode->getData()) {
currNode = currNode->getLeft();
}
else if (currNode->getData() < krone) {
currNode = currNode->getRight();
}
else {
// krone == currNode->getData()
return currNode;
}
}
// krone not found in tree
return nullptr;
}
class MinHeap : public BST {
public:
MinHeap() : BST() {}
void insertNode(const Krone& krone) {
BSTNode* node = new BSTNode(krone);
if (isEmpty()) {
root = node;
}
else {
BSTNode* parent = nullptr;
BSTNode* currNode = root;
queue<BSTNode*> bfsQueue;
bfsQueue.push(currNode);
while (!bfsQueue.empty()) {
parent = currNode;
currNode = bfsQueue.front();
bfsQueue.pop();
if (currNode->getLeft() == nullptr) {
currNode->setLeft(node);
break;
}
else if (currNode->getRight() == nullptr) {
currNode->setRight(node);
break;
}
bfsQueue.push(currNode->getLeft());
bfsQueue.push(currNode->getRight());
}
if (node->getData() < parent->getData()) {
swap(node->setData(parent->getData()), parent->setData(node->getData()));
heapify(parent);
}
}
}
void deleteNode(BSTNode* nodeToDelete) {
if (nodeToDelete == nullptr) {
return;
}
BSTNode* lastNode = root;
queue<BSTNode*> bfsQueue;
bfsQueue.push(lastNode);
while (!bfsQueue.empty()) {
lastNode = bfsQueue.front();
bfsQueue.pop();
if (lastNode->getLeft() != nullptr) {
bfsQueue.push(lastNode->getLeft());
}
if (lastNode->getRight() != nullptr) {
bfsQueue.push(lastNode->getRight());
}
}
nodeToDelete->setData(lastNode->getData());
if (lastNode == root) {
root = nullptr;
}
else {
BSTNode* parent = root;
while (parent != nullptr) {
if (parent->getLeft() == lastNode || parent->getRight() == lastNode) {
break;
}
else if (lastNode->getData() < parent->getData()) {
parent = parent->getLeft();
}
else {
parent = parent->getRight();
}
}
if (parent->getLeft() == lastNode) {
parent->setLeft(nullptr);
}
else {
parent->setRight(nullptr);
}
heapify(parent);
}
delete lastNode;
}
private:
void heapify(BSTNode* node) {
if (node == nullptr) {
return;
}
BSTNode* smallest = node;
if (node->getLeft() != nullptr && node->getLeft()->getData() < smallest->getData()) {
smallest = node->getLeft();
}
if (node->getRight() != nullptr && node->getRight()->getData() < smallest->getData()) {
smallest = node->getRight();
}
if (smallest != node) {
swap(node->getData(), smallest->getData());
heapify(smallest);
}
}
};
int main() {
// Create MinHeap object
MinHeap heap;
![1.
2. Kr 23.44
Kr 57.12
3.
4. Kr 68.99
5. Kr 111.22
Kr 87.43
6. Kr 44.55
7. Kr 77.77
8. Kr 18.36
9. Kr 543.21
10. Kr 20.21
11. Kr 345.67
12. Kr 36.18
13. Kr 48.48
14. Kr 101.00
15. Kr 11.00
16. Kr 21.00
17. Kr 51.00
18. Kr 1.00
19. Kr 251.00
20. Kr 151.00](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa72e8965-bd79-4464-a740-a72095a0be2c%2F98bd439c-9b1c-47d1-a2b2-2a6745a25b81%2F1f1bwbb_processed.png&w=3840&q=75)
![• Derive a MinHeap class from the BST class of your Lab 4 code.
• Define/Override only the Search/Insert/Delete methods in the new class.
. Write a new main for this lab which:
• Will only be a test program for the MinHeap.
. Declares and creates a MinHeap object as necessary.
• Declares and creates the Krone objects as necessary.
• Inserts the 20 Krone objects specified in Lab 4 in the same order.
• Performs all 4 traversals after the inserting the 10th and the last objects - in total there will be 8 outputs which should be clearly demarcated.
• No user input is necessary, no data validation is necessary.
. For submission - upload all class files from Lab 4 as necessary as well as your new MinHeap class and the main. Remember to also include adequate
number of screenshots of the program execution.
• The Discussion forum will be monitored and responded to all week during the Finals. Office Hours will only be held on MTW. For clarifications, post your
questions on the Discussion forum first.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa72e8965-bd79-4464-a740-a72095a0be2c%2F98bd439c-9b1c-47d1-a2b2-2a6745a25b81%2Fiflalpt_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)