旧题重开『一个数组中有N个元素,找出其中重复次数最多的那个元素?』要求有变,该怎么处理

旧题重开『一个数组中有N个元素,找出其中重复次数最多的那个元素?』要求有变
之前在CSDN上提过类似的问题,就是:一个数组中有N个元素,找出其中重复次数最多的那个元素?原来的问题的假设条件是***没有重复次数相同的两个不同元素***,例如{1,1,2,2,4,4,4,4,5,5,6,6,6},就是要找出4,之前很感谢guoshanhe提供的算法,虽然不一定是最好的,但是对于我却是实用的。
        但是我现在得到的原始数组中***存在重复次数相同的两个不同元素***,例如{1,1,2,2,2,3,3,3,4,4,4},这样的话就需要把2,3,4都找出来。这样的话,guoshanhe提供的算法就不是很好了。并且数组中的情况是不确定的,也有可能是{1,1,1,2,2,3,3,3},所以算法要有一定的通用性。
        另外,数组中的元素是任意顺序的,也就是没有经过排序的,如果这样难以实现的话,可以先实现已经排序了的,就像我举出的例子那样。
        最后还有一点要说明的是,最好使用C实现的,不要用C++,因为这个算法我最终是要移植到嵌入式系统中的,有些东西不支持,我之前让一个朋友写过一个算法,可是里面用到了new和delete这样的关键字,是我的系统不支持的,只有再次到CSDN上麻烦各位大侠了,小弟谢谢先~~~

------解决方案--------------------
//一个数组中有N个元素,找出其中重复次数最多的那个元素

#include <stdio.h>
#include <stdlib.h>

int array[]={1,2,4,3,7,4,6,4,3,2,1,5,7,4,8,4,6,7,4,5,7,8,4,7,7,6,7,4,3,7};


typedef struct list_node
{
int element; //元素值
int count; //数组中出现次数
struct list_node* next;
}list_node;


list_node* head = NULL;


void insert(int val)
{


list_node* tmp = head;
list_node* pre = NULL;
if(tmp == NULL) //链表为空
{
head = (list_node*)malloc(sizeof(list_node));
head-> element = val;
head-> count = 1;
head-> next = NULL;
return;
}
while(tmp != NULL)
{

if(tmp -> element == val)
{
tmp -> count ++;
return;
}
else if(tmp -> element > val)
{

//产生一个新的链表节点
if(pre == NULL) //tmp为head
{
pre = (list_node*)malloc(sizeof(list_node));
pre-> element = val;
pre-> count = 1;
pre-> next = tmp;
head = pre;
return;
}
else
{
pre-> next = (list_node*)malloc(sizeof(list_node));
pre-> next-> element = val;
pre-> next-> count = 1;
pre-> next-> next = tmp;
return;
}
}
else
{
pre = tmp;
tmp = tmp -> next;
}
}
if(tmp == NULL) //加在链尾
{
pre-> next = (list_node*)malloc(sizeof(list_node));
pre-> element = val;
pre-> count = 1;
pre-> next-> next = NULL;
}
}





int main()
{

int i;
int n = sizeof(array)/4;

list_node* cur = NULL;
list_node* max_head = NULL; //出现次数最多元素组成的链
list_node* max_tail = NULL;
int max_cnt = 0;
for(i = 0; i < n; i++)
{
insert(array[i]);
}

//寻求count值最大的节点
max_head = head;
max_tail = head;

if(head != NULL)
{
max_cnt = head -> count;
cur = head -> next;
max_tail -> next = NULL;

}

while(cur != NULL)
{
if(max_cnt > cur-> count)
{
//do nothing
cur = cur -> next;
}
else if(max_cnt == cur-> count)
{
//add the node to max_head list
max_tail -> next = cur;
max_tail = cur;
cur = cur -> next;
max_tail -> next = NULL;
}
else
{
//reconstruct the max_head list
max_cnt = cur -> count;
max_head = cur;
max_tail = cur;
cur = cur -> next;
max_tail -> next = NULL;
}
}

//output the result
cur = max_head;
printf( "the max count is %d\n ",max_cnt);
while(cur != NULL)
{
printf( "%d\n ",cur-> element);