I have an array
A[4]={4,5,9,1}
I need it to give the first 3 top elements like 9,5,4
I know how to find the maximum element, but how to find the 2nd and 3rd maximum?
ie if
max=A[0]
for(i=1;i<4;i++)
{
if (A[i]>max)
{
max=A[i];
location=i+1;
}
}
actual sorting is not suitable for my application because
the position number is also important to me, i.e. I need to know in what positions the first maximum 3 occurs, here it is in the 0th, 1st and 2nd positions ... so I think about the logic
that after getting the maximum value, if I could put 0 in this place and could apply the same steps for this new array, that is {4,5,0,1}
But I'm a little confused how to put my logic in code
source
share