Advertisement
Matteogoli

stupid sort

Feb 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. def swap(l, a, b):
  2.     tmp = l[a]
  3.     l[a] = l[b]
  4.     l[b] = tmp
  5.  
  6. def is_sorted(l):
  7.     for i in range(0, len(l) - 1):
  8.         if(l[i] > l[i + 1]):
  9.             return False
  10.     return True
  11.  
  12. def stupid_sort(l):
  13.     swap(l, random.randint(0, len(l) - 1), random.randint(0, len(l) - 1))
  14.     if not is_sorted(l):
  15.         stupid_sort(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement