Question: Write a program to test if a given array satisfies the constraints of min heap and max heap. bool isMinHeap(int arr[],int size); bool isMaxHeap(int arr[],int

Write a program to test if a given array satisfies the constraints of min heap and max heap.

bool isMinHeap(int arr[],int size); bool isMaxHeap(int arr[],int size); 

Also write code for this function:-

int heapPlay(int arr[],int size); 

The function returns an integer as follows:-

1. If the array is a min heap return the minimum element

2. If the array is a max heap return maximum element

3. Return 0, if the array is a min heap and a max heap

4. Return -1, if the array is neither a min heap nor a max heap

Ex.

Input - Contains size on line 1, an array on line 2.

Output - We will test your three methods

Input -

3

1 2 3

Output -

isMinHeap -> true

isMaxHeap -> false

heapPlay -> 1

Sample Input 1:

1 5

Sample Output 1:

1 1 0

Sample Input 2:

3 9 8 7

Sample Output 2:

0 1 9

Write this in c++ please

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 Databases Questions!