angryatti

BubbleSort - Hardened Wayv2

Sep 1st, 2024 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #second fixed edition
  2.  
  3. from multiprocessing import Process
  4. import random
  5. import math
  6.  
  7.  
  8. def switch_item(a,b):
  9.     return b,a
  10. def bubble_sort(array):
  11.     for i in range(len(array)-1,0,-1):
  12.        for j in range(0, i):
  13.                if array[j] > array[j+1]:
  14.                    array[j], array[j+1] = switch_item(array[j], array[j+1])
  15.                    #or     array[j], array[j+1] = array[j+1], array[j]
  16.  
  17.     print("Array sorted: ", array)
  18. def rand_array():
  19.     arrayofrand = list()
  20.     temprand = 1.0
  21.     for a in range(20):
  22.         temprand = random.random()
  23.         arrayofrand.append(math.floor(temprand*1000))
  24.     return arrayofrand
  25.  
  26.  
  27. if __name__ == '__main__':
  28.  
  29.    
  30.     p = Process(target=bubble_sort, args=(rand_array(),))
  31.     p.start()
  32.     p.join()
Advertisement
Add Comment
Please, Sign In to add comment