Thursday, March 31, 2016

bubble sort - o(n*n)

#!/usr/bin/python

def bubble_sort(arr):
for i in range(0, len(arr)):
for j in range(i, len(arr)):
if arr[i] > arr[j]:
arr[j], arr[i] = arr[i], arr[j]

arr= [8, 3, 0, 8, 9, 3, 0, 5]
bubble_sort(arr)
print arr

No comments:

Post a Comment