I believe that this happens because of lines 18 and 20. In line 18 Index changes from 0 to 6, in line 20 you access to List[Index+1], if Index equals 6 you go beyond list and start to analyze something else (0 in your case).
To correct this modify line 18 to for (int Index = 0; Index < 6; Index++)
And general advice: introduce const Length = 7, and work with it. It will be easier for you to update the code in future. Try to avoid literals.
oh i see, thank you very much for the explanation. And thanks for the advice about the constants but since this is not for any particular purpose but just to learn how to implement algorithms in c, i simply used 7. Cheers!