Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- n = []
- for i in range(int(input("Enter your array length: "))):
- n.append(int(input("Enter some data: ")))
- print(f"Your array is: {n}")
- #Bubble sort
- start = time.time()
- def bubble_sort():
- swp_count = 0
- for run in range(len(n)-1):
- for x in range(len(n)-1) :
- if n[x] > n[x+1]:
- swp_count += 1
- n[x], n[x+1] = n[x+1],n[x]
- print(f"Your sorted array is: {n}")
- print(f"Sorted {swp_count} times.")
- bubble_sort()
- end = time.time()
- print(f"Bubble sort was during {end-start} seconds.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement