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

 P14.34. Coding: Heap Utility Function Consider this Entry structure for a

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!