Advertisement
Guest User

SR2019-Buggy-Code

a guest
Nov 12th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Implementation of a bubble sort.
  2. # This code is syntactically correct, however there are a couple of
  3. # problems that prevent it from producing the desired output.
  4. # Find these errors and correct them, writing a comment explaining
  5. # what the error was.
  6.  
  7. def swap_values(i1, i2, list_):
  8.     list_[i1], list_[i2] = list_[i1], list_[i1]
  9.     return list_
  10.  
  11. def sort(values):
  12.     for pass_num in range(1, len(values)):
  13.         pass_size = len(values) - pass_num
  14.         for i in range(pass_size + 1):
  15.             if values[i] > values[i + 1]:
  16.                 values = swap_values(i, i, values)
  17.     return values
  18.  
  19. print sort([3, 45, 212, 31, 53, 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement