Your cart is currently empty!
These must be completed and shown to your lab TA either by the end of this lab, or at the start of your next lab. You may work in groups of up to two people. Download binaryHeap.cpp from the course web page under Lab 4. You need to complete the printHeap function so that…
These must be completed and shown to your lab TA either by the end of this lab, or at the start of your next lab. You may work in groups of up to two people.
0
*2
**4
***7
***6
**3
***8
*1
**9
**5
First print the current element, then its left subtree, and then its right subtree. Preface each element with a number of asterisks equal to its depth in the heap.
5
1
9
0
3
8
2
6
4
7
If you rotate this output by 90 degrees, you can see the tree. Can you modify the code you wrote for Question 1 to generate this result?
The remaining questions are designed to emphasize the fact that often the simplest algorithm is best.
//PRE: heap points to an array representing a heap
//POST: all elements with key value = key have been removed from
Are the remove tests printing out correctly? Be sure to draw a picture and refer to your notes if you’re unsure what to expect.
1Implement the following function:
//PRE: heap1 and heap2 contain size1 and size2 elements respectively.
//POST: output a new heap (whose size is size1+size2) containing all
int* mergeHeap(int* heap1, int* heap2, int size1, int size2);
Is the merge test printing out correctly? Be sure to draw a picture and refer to your notes if you’re unsure what to expect.
2