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.
defcountSwaps(a):temp=0count=0i=0whilei<len(a):idx=0whileidx<len(a)-1:ifa[idx]>a[idx+1]:count=count+1temp=a[idx]a[idx]=a[idx+1]a[idx+1]=tempidx=idx+1i=i+1print("Array is sorted in "+str(count)+" swaps.")print("First Element:",a[0])print("Last Element:",a[len(a)-1])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →