This uses the fastest possible associative data structure: an array. That is all you need in this case because you are only dealing with numbers. It could use more memory than the map depending on the ratio of n to the max value of x. It runs in 40% the time of the STL map based version. (Both compiled with -O3)
#include <stdio.h>
#include <stdlib.h>
#define MAX_VAL 10000000
int main() {
unsigned int n, x, size, mode=0;
unsigned int* counts = calloc(MAX_VAL, sizeof(unsigned int));
freopen("mode.in", "rt", stdin);
scanf("%d\n", &n);
while (n--) {
scanf("%d\n", &x);
if (( size = ++counts[x]) > mode) mode = size;
}
printf("%d\n", mode);
return 0;
}
Just up and learn the STL it will save you a *ton* of time. It will give you tested, debugged, and optimized data structures and algorithms. That is what you want when you are working under pressure. You don't want to lose because you made a stupid error in your linked list or binary tree, you want to be solving the problem. You can find plenty of
STL tutorials on google.