You are viewing a single comment's thread. Return to all comments →
#python3 def countSwaps(a): numSwaps=0 n=len(a) for i in range(n): for j in range(0, n-1-i): if a[j] > a[j+1]: numSwaps+=1 a[j+1], a[j]=a[j], a[j+1] else: pass last_element = a[-1] first_element = a[0] print(f'Array is sorted in {numSwaps} swaps.\nFirst Element: {first_element}\nLast Element: {last_element}')
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 →