Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Why is it important to begin meetings on time?

Answered: 1 week ago