Question: You are given an integer array intArray and its size MAX_SIZE. Write a C++ program which determines whether there is any number in intArray which

You are given an integer array intArray and its size MAX_SIZE. Write a C++ program which determines whether there is any number in intArray which occurs more than 50% of times (that is, more than ceiling(n/2) times) such an element is called a Popular Element. So if n =10, and one of the elements in intArray occurs more than 5 times, then it is a Popular element. If n=11, and one of the elements occurs more than 6 times then it is a Popular element.

For example: 1 1 1 4 5 1 7 8 1 1 (array size is 10 and 1 occurs more than 5 times. 1 is a popular element) 2 2 2 4 2 1 7 8 2 2 2 (array size is 11 and 2 occurs more than 6 times so 2 is a popular element) The program should either print the popular element or report that none exists.

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!