Acer1968

Třídění pole - InformatikaSMisom

Oct 27th, 2021
843
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. def mybubble(array):
  4.     sorted_array = [array[0]]
  5.     for x in array[1:]:
  6.         bigger_found = False
  7.         for y in sorted_array:
  8.             if x < y:
  9.                 sorted_array.insert(sorted_array.index(y),x)
  10.                 bigger_found = True
  11.                 break
  12.         if not bigger_found:
  13.             sorted_array.append(x)
  14.     return sorted_array
  15.  
  16. arr = [random.choice(range(50)) for i in range(20)]
  17. print(arr)
  18. sort_arr = mybubble(arr)
  19. print(sort_arr)
RAW Paste Data