Gets the highest number of occurrences in the array

Source: Internet
Author: User

- (void) viewdidload{intArray[] = {0,1,1,2,3,4,5,6,6,6,7,7,7,7,7,7,9,9,9,9,9}; Search (Array,sizeof(array)/sizeof(*array));}
voidSearchintA[],intLen) {    intI, index,//Temp array subscript, a value corresponding to array i. Max =0;//The value of the temp corresponding to the position, both occurrences.         inttemp[ +] = {0};//defines an array of 1000 elements with the initial value set to 0     for(i =0; i < Len; i++) {Index=A[i]; Temp[index]++;//which element appears most, resulting in temp[index] value Max    }     for(i =0; I < +; i++)//traverse the entire array to find the element with the largest value    {        if(Max <Temp[i]) {Max=Temp[i]; }    }     for(i =0; I < +; i++)//traverses the entire array, with the value of the bottom of the largest element of the output value plus 1    {        if(max = =Temp[i]) {printf ("%d\n", i);//that is, the most frequently occurring element        }    }}

Gets the highest number of occurrences in the array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.