Ad
  • Custom User Avatar

    It seems to me that your algorithm is flawed - you do not perform a swap every single time regardless of conditions.

    Take the list [103, 87, 113] for example:

    1. We compare the two numbers 103 and 87. Since 103 is indeed greater than 87 we perform a swap.
    2. The list now becomes [87, 103, 113] and we compare 103 and 113. We only perform a swap if the number at the left hand side (103) is greater than the number at the right hand side (113). Since that is not the case, we do not perform a swap.
    3. Therefore, after one complete pass, the list becomes [87, 103, 113].

    Hope that helps :)