#include<stdio.h>
#include<stdlib.h>
struct Node
{
int e,n;
Node *next;
};
int L;
Node* A;
int X;
int main()
{
int e;
Node* p,* q,* r;
A=NULL;
while(scanf("%d",&L)==1){
scanf("%d",&e);
A=(Node *)malloc(sizeof(Node));
A->e=e;
A->n=1;
A->next=NULL;
L--;
while(L>0){
p=A;
scanf("%d",&e);
while(p!=NULL){
if(p->e==e){
p->n++;
break;
}
q=p;p=p->next;
}
if(p==NULL){
r=(Node *)malloc(sizeof(Node));
r->e=e;
r->n=1;
r->next=NULL;
q->next=r;
}
L--;
}
int maxn=0;
p=A;
while(p!=NULL){
if((p->n)>maxn){
maxn=p->n;
X=p->e;
}
p=p->next;
}
printf("%d\n",X);
//释放A占用的内存
p=A;
while(p){
q=p;
p=p->next;
free(q);
}
A=NULL;
}
return 0;
}
//此程序的缺陷:如果有两个最大频率的话,无法输出,再此没做改进
#include<stdio.h>
#include<stdlib.h>
typedef struct lnode
{
int e;
int len;
struct lnode *next;
}lnode;
int main()
{
int n,e,x;
lnode *a,*p;
lnode *q;
lnode *a1,*a2;
lnode *r,*s,*r1;
a=NULL;
p=NULL;
printf("input n:");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("please input no.%d:",i+1);
scanf("%d",&e);
if(a==NULL)
{
a=(lnode*)malloc(sizeof(lnode));
a->e=e;a->len=1;a->next=NULL;
}
else
{
a2=(lnode*)malloc(sizeof(lnode));
a2->e=e;a2->len=1;a2->next=NULL;a->next=a2;a=a2;
}
if(p==NULL)
{
p=(lnode*)malloc(sizeof(lnode));
p->e=e;p->next=NULL;p->len=1;
}
else
{
q=p;
while(q)
{
if(q->e==e)
{
q->len++;
break;
}
s=q;q=q->next;
}
if(q==NULL)
{
r1=(lnode*)malloc(sizeof(lnode));
r1->e=e;r1->next=NULL;r1->len=1;
s->next=r1;
}
}
}
// while(a)
// {printf("%d",a->e);a=a->next;}
// while(p)
// {printf("%d %d",p->e,p->len);p=p->next;}
int max=0;
while(p)
{
if(p->len>max)
{
max=p->len;
x=p->e;
}
p=p->next;
}
printf("%d\n",x);
return 0;
}