Skip to content

Instantly share code, notes, and snippets.

@zigzackey
Created March 29, 2016 10:32
Show Gist options
  • Save zigzackey/b963e947c4b0c1bd8725 to your computer and use it in GitHub Desktop.
Save zigzackey/b963e947c4b0c1bd8725 to your computer and use it in GitHub Desktop.
def bubbleSort(R, N):
flag = True
cnt = 0
while flag == True:
flag = False
for j in range(N - 1, 0, -1):
if R[j] < R[j - 1]:
tmp = R[j]
R[j] = R[j - 1]
R[j - 1] = tmp
cnt = cnt + 1
flag = 1
print(" ".join(map(str, R)))
return cnt
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
ans = bubbleSort(A, n)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment