Ad
  • Custom User Avatar

    Unfortunately you cannot guarantee reversal with a sorting algorithm. Sorting works by testing two values; if the returned number is > 0, it will swap the values, if <= 0 it will leave them as-is (a generalisation, but you get the idea). The only case where your code would work is if the first and last values are tested (and swapped), then the second and second-to-last values are tested (and swapped), and so on. This tends not to be the case, however. It will test each value a number of times, against different values until it finds the right place for it.

    I had originally tried a similar solution to yours, but found it severely lacking, unfortunately. (And I'm the author! ;P)

    The reason it seems as though it's the "last" test that fails is, because of how the tests are written, when any test fails the testing will stop. So any failing test will look like the last test. There are 3 basic tests, and then 10 randomly-generated ones; perhaps those are giving you problems?