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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started