If you want this code to work, I think the problem is here:
if (secondlargest < arr[i] && largest != arr[i]) { thirdlargest = secondlargest; secondlargest = arr[i]; if (thirdlargest < arr[i] && secondlargest != arr[i]) thirdlargest = arr[i]; }
The problem is that you are setting thirdLargest as secondLargest, which has already been defined as less than arr [i]. Then you check whether thirdLargest will be smaller than arr [i] (which is guaranteed, since it was set to the second largest in the external state), and then setting it to arr [i]. Try to remove
if (thirdlargest < arr[i] && secondlargest != arr[i]) thirdlargest = arr[i];
and if that doesn't work, try adding a third separate condition to cover cases where arr [i] is less than the second but more than the thirdGreatest. (see Jens above), something like:
source share