Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You need to find if there any mistake in source codes. It is preferred that your answer will contain three parts: 0. .Identification of mistake/error(it

You need to find if there any mistake in source codes. It is preferred that your answer will contain three parts: 0. .Identification of mistake/error(it can be any type of error or problem which may result in incorrect result) 1. Explain why it is an error or a problem 2. Correct the problem or give an alternative solution.

heaptype.h #ifndef HEAPTYPE_H_INCLUDED #define HEAPTYPE_H_INCLUDED template struct HeapType { void ReheapDown(int root, int bottom); void ReheapUp(int root, int bottom); ItemType* elements; int numElements; }; #endif

#include "heaptype.h" template void Swap(ItemType& one, ItemType& two) { ItemType temp; temp = one; one = two; two = temp; } template void HeapType::ReheapDown(int root, int bottom) { int maxChild; int rightChild; int leftChild; leftChild = root*2+1; rightChild = root*2+2; if (leftChild <= bottom) { if (leftChild == bottom) maxChild = leftChild; else { if(elements[leftChild]<=elements[rightChild]) maxChild = rightChild; else maxChild = leftChild; } if (elements[root] < elements[maxChild]) { Swap(elements[root], elements[maxChild]); ReheapDown(maxChild, bottom); } } } template void HeapType::ReheapUp(int root, int bottom) { int parent; if (bottom > root) { parent = (bottom-1) / 2; if (elements[parent] < elements[bottom]) { Swap(elements[parent], elements[bottom]); ReheapUp(root, parent); } } }

..

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 Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions