We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defbubble(arr):count_swap=0fornuminrange(len(arr)-1,0,-1):foriinrange(num):ifarr[i]>arr[i+1]:arr[i],arr[i+1]=arr[i+1],arr[i]count_swap+=1returncount_swapprint"Array is sorted in {} swaps.".format(bubble(a))print"First Element: {}".format(a[0])print"Last Element: {}".format(a[-1])
Day 20: Sorting
You are viewing a single comment's thread. Return to all comments →
Python way