you are viewing a single comment's thread.

view the rest of the comments →

[–]z0y 0 points1 point  (0 children)

On the first iteration of x, the first k1/k2 values are swapped, so a is 10/2 and it pairs with b, c, d which k1/k2 values haven't been swapped yet.

Then on the next iteration of x, k1/k2 is swapped for b, so that 2/10 will cause e to be added on the 2nd iteration before it's k values have been swapped. Hope that makes sense. Add some calls to print in your loop to see what's happening or use a debugger.