Advertisement
angryatti

BubbleSort - Hardened Way

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