Advertisement
Acer1968

Třídění pole - InformatikaSMisom

Oct 27th, 2021
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement