-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2ndhighestfreq.c
62 lines (61 loc) · 965 Bytes
/
2ndhighestfreq.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<stdio.h>
int main()
{
int arr[]={1,2,8,2,2,2,2,5,1};
int length=sizeof(arr)/sizeof(arr[0]);
int max[length];
max[0]=0;
int fr[length];
int visited=-1;
for(int i=0;i<length;i++){
int count=1;
for(int j=i+1;j<length;j++){
if(arr[i]==arr[j]){
count++;
fr[j]=visited;
}
}
if (fr[i]!=visited)
fr[i]=count;
}
printf("---------------------\n");
printf("Element|Frequency\n");
printf("---------------------\n");
for(int i=0;i<length;i++)
{
if(fr[i]!=visited)
{
printf("%d",arr[i]);
printf("|");
printf("%d\n",fr[i]);
}
}
printf("---------------------\n");
int k=0;
for(int i=0;i<length;i++)
{
if(fr[i]!=visited)
{
if(max[k]<fr[i])
{
max[k+1]=fr[i];
k++;
}
}
}
int i;
for(i=0;i>length;i++)
{
int count=0;
if(fr[i]!=visited)
{
count++;
if(count==1)
{
break;
}
}
}
printf("The 2nd max value of arr %d is %d",arr[i],max[k-1]);
return 0;
}