Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There's an error in the code that I can't spot that's leaving spaces. Please help! Expected and error output shown below: #include #include #include using

There's an error in the code that I can't spot that's leaving spaces. Please help!

Expected and error output shown below: image text in transcribed

#include

#include #include using namespace std; void inputHeap(vector &heap); void print(vector v); bool maxHeap(vector heap); void heapify(vector &heap); void inputCommand(vector &heap); void insert(vector &heap, int node_val); void deleteNode(vector &heap, int node_val); void update(vector &heap, int node_index, int new_val); void displayMax(vector heap); void deleteMax(vector &heap);

int main() { vector heap; inputHeap(heap); if (maxHeap(heap)) { cout

inputCommand(heap); return 0; }

void inputHeap(vector &heap) { int cycles; cin >> cycles; heap.resize(cycles + 1); int input; for (int x = 1; x > input; heap[x] = input; } }

void print(vector v) { for (int x = 1; x

bool maxHeap(vector heap) { int parent; int l_child; int r_child; for (int x = heap.size() / 2; x > 0; x--) { parent = x; l_child = x * 2; r_child = x * 2 + 1; if (l_child heap[parent]) { return false; } } if (r_child heap[parent]) { return false; } } } return true; } void heapify(vector &heap) { int parent; int currVal; bool is_heap; int l_child; int r_child;

while (!maxHeap(heap)) { for (parent = heap.size() / 2; parent > 0; parent--) { is_heap = false; l_child = 2 * parent; r_child = 2 * parent + 1;

while (!is_heap && l_child = heap[l_child]) { is_heap = true; } else { swap(heap[parent], heap[l_child]); } } } } } } void insert(vector &heap, int node_val) { heap.push_back(node_val); heapify(heap); } void deleteNode(vector &heap, int node_val) { for (int x = 1; x &heap, int node_index, int new_val) { heap[node_index] = new_val; heapify(heap); }

//function displays maximum value in the heap void displayMax(vector heap) { cout &heap) { heap[1] = heap.back(); heap.pop_back(); heapify(heap); } void inputCommand(vector &heap) { int num_commands; cin >> num_commands;

string command; int node_val; int update_val;

for (int x = 0; x > command;

if (command == "insert") { cin >> node_val; insert(heap, node_val); } else if (command == "delete") { cin >> node_val; deleteNode(heap, node_val); } else if (command == "update") { cin >> node_val >> update_val; update(heap, node_val, update_val); } else if (command == "display") { print(heap); } else if (command == "displayMax") { displayMax(heap); } else if (command == "deleteMax") { deleteMax(heap); } } }

Expected output? 1 This is NOT a heap. 399 Actual output ? 1ThisisNOTaheap.399 Difference

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

What is Centrifugation?

Answered: 1 week ago

Question

To find integral of ?a 2 - x 2

Answered: 1 week ago

Question

To find integral of e 3x sin4x

Answered: 1 week ago

Question

To find the integral of 3x/(x - 1)(x - 2)(x - 3)

Answered: 1 week ago

Question

What are Fatty acids?

Answered: 1 week ago

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago