Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

P14.34. Coding: Heap Utility Function Consider this Entry structure for a heap represented as a vector : struct Entry { int data; / / Possibly

image text in transcribed
P14.34. Coding: Heap Utility Function Consider this Entry structure for a heap represented as a vector: struct Entry { int data; / / Possibly additional fields, but / / none relevant to this problem! The heap uses 1-based indexing (i.e., the root is at index 1 in the heap). Now, complete the function bool equalDepthLeaves (const std: : vector &heap, int node) below so that it has the behaviour: given an initial index in the heap, return true if the subtree rooted at that index is perfect and false otherwise. For example, for the heap containing five entries 10, 20, 50, 30, 90 and initial index 2 referring to the data 20, the result should be true because the 3-node subtree at the initial index is perfect, but for the root index 1 the result should be false. NOTES: . No two valid Entrys in a heap will have the same data. . Indexes passed as arguments to your function will refer to real nodes in the heap. . Index 0 of heap is unused and ignored. . heap. size ( ) is the size of the vector, which is one more than the number of valid entries in the heap

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions