Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # 1
  2. def checkAdj(L):
  3.   n = len(L)
  4.   for i in range(n-1):
  5.     print(min(L[i], L[i+1]))
  6.  
  7. # 2
  8. def bubbleSwap(L):
  9.   # every execution will put the largest item to the right-most position
  10.   n = len(L)
  11.   for i in range(n-1):
  12.     if L[i] > L[i+1]:
  13.       temp = L[i+1]
  14.       L[i+1] = L[i]
  15.       L[i] = temp
  16.   # no output since the original array was modified in-place
  17.  
  18. # 3
  19. def bubbleSort(L):
  20.   # do bubble swap for len(L) - 1 times
  21.   n = len(L)
  22.   for j in range(n-1):
  23.     for i in range(n-j-1):
  24.       if L[i] > L[i+1]:
  25.         temp = L[i+1]
  26.         L[i+1] = L[i]
  27.         L[i] = temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement