Explanation:
P.S. This is going to be really long!
So we start with Index = 5, Position = False and Valid = False. Now the way this algorithm works is it checks Sam's score, i.e. NewScore with HighScore(5) which is the last score on the leaderboard BEFORE Sam's score is added. Then if Sam's score is greater, it copies Sam's score into the 5th position of the array Highscore. Valid = True means Sam's score has made it onto the leaderboard, and Valid = false means it hasn't. Now consider this code:
IF NewScore > Highscore(5)
........Valid = True
........Highscore(5) = NewScore
....ENDIF
See the first line says "Is Sam's score greater than the last score in the array Highscore?" which in this case is Col's score of 4. Well yes Sam's score is 15 and therefore his score is definitely large enough to make it onto the leaderboard! So since his score is large enough we set Valid = true, now this is particularly important because if you look at the next line of code right after it begins with
IF Valid = true. This is there to ensure that our simplified bubble sort only occurs IF Sam's score has made it onto the leaderboard, because there would be no point in performing a sort if Sam's score is too low.
Then Highscore(5) = Newscore just means we are setting the 5th position in the array Highscore to equal Sam's score.
Thus so far what have we done? Well we've decided that Sam's score is large enough to be on the leaderboard and thus we have placed his score in the last position because his score is at least guaranteed to be in last place.
Now onto the next part of the algorithm, this part is the most confusing so you must think through what I'm saying carefully.
We firstly see the line WHILE Position = False and Index <> 1. Now Position will equal True if Sam's score is in the correct position on the leaderboard and False if his score isn't in the correct position. However Sam's score is in last place at the moment but is it meant to belong there? His score is actually higher than Chris and Lucky for example!
Now we need the Position = False in the loop because we only want to swap the position of Sam's score WHILE his score is in the wrong place because why would we want to swap otherwise? The question asks us to put his score in the correct place.
Now the <> in Index <> 1 just means
does not equal. This is relevant because suppose we've performed the sort a few times and Sam's score ends up in first place. There is no more positions in the array for us to swap Sam's position with. This is seen in the next line IF Newscore > Highscore(Index-1) as in this line we determine if Sam's score is larger than the one before it, but in first place there is no score before Sam's, and hence we need Index <> 1 in the While loop.
So in English it translates to "WHILE Sam's score is in the incorrect position AND his score isn't in first place"
Onto the next part, now this is the actually Physical Sort that you were talking about. It checks Sam's score with the one before it and if Sam's score is greater, his score is swapped as can be seen through the
Swap subroutine.
However after the swap has occurred, Sam's score is in the different position right? So we must reduce the Index by 1, thus Index = Index - 1. Recall INDEX is the Position of Sam's score, so the position of his score will reduce by 1 in the array each time the swap occurs, and so right after the swap we do Index = Index - 1.
After that we are hit with ELSE, Position = True. The IF Statement IF Newscore > Highscore(Index - 1) is saying "IF Sam's score is greater than the one before it", but what if it isn't?? What if Sam's Score < Highscore(Index - 1)??
In that case it means Sam's score is actually in the correct position! because the rest of the array is already sorted and therefore if Sam's score is less than the one before it, it must also be less than every other score even before that.
AND Tada! There you have it!. The whole algorithm explained line by line in English. I hope you understand
EDIT: I almost threw my laptop in anger after this website logged me out right AFTER I finished typing everything. Luckily it was saved phew!