Please find my answer as following:
Input - 13, 2, 41, 5 , 46, 7
first_big = 12 // first big
second_big = 2 // second big
for (i = 2; i < size - 1; i++)
{
if (arr[i] > first_big)
{
second_big = first_big;
first_big = arr[i];
}
}
First iteration:
second_big = 12
first_big = 41
Second iteration:
No change
Third iteration:
second_big = 41
first_big = 46
This is final result.
If someone has better logic to solve this problem then please share.