Thefaceofbo

BubbleSort (py)

Nov 9th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # Function Definition
  2. def bubbleSort(A):
  3.    # Error Checks
  4.    if type(A) != list:
  5.       return [False, A]
  6.    n = len(A)
  7.    if n == 0:
  8.       return [False, A]
  9.    for val in A:
  10.       if type(val) != int and type(val) != float:
  11.          return [False, A]
  12.    # Duplicate and sort
  13.    final = list(A)
  14.    for x in range(0,n,1):
  15.       for y in range(0,n,1):
  16.          if final[x] < final[y]:
  17.             temp = final[x]
  18.             final[x] = final[y]
  19.             final[y] = temp
  20.    return [True, final]
Advertisement
Add Comment
Please, Sign In to add comment