@@ -6,13 +6,13 @@ def bubble_sort(collection):
6
6
:return: the same collection ordered by ascending
7
7
8
8
Examples:
9
- >>> bubble_sort([0, 5, 3, 2 , 2])
9
+ >>> bubble_sort([0, 5, 2, 3 , 2])
10
10
[0, 2, 2, 3, 5]
11
11
12
12
>>> bubble_sort([])
13
13
[]
14
14
15
- >>> bubble_sort([-2, -5 , -45 ])
15
+ >>> bubble_sort([-2, -45 , -5 ])
16
16
[-45, -5, -2]
17
17
18
18
>>> bubble_sort([-23, 0, 6, -4, 34])
@@ -29,11 +29,14 @@ def bubble_sort(collection):
29
29
swapped = True
30
30
collection [j ], collection [j + 1 ] = collection [j + 1 ], collection [j ]
31
31
if not swapped :
32
- break # Stop iteration if the collection is sorted.
32
+ break # Stop iteration if the collection is sorted.
33
33
return collection
34
34
35
35
36
36
if __name__ == "__main__" :
37
+ import time
37
38
user_input = input ("Enter numbers separated by a comma:" ).strip ()
38
39
unsorted = [int (item ) for item in user_input .split ("," )]
40
+ start = time .process_time ()
39
41
print (* bubble_sort (unsorted ), sep = "," )
42
+ print (f"Processing time: { time .process_time () - start } " )
0 commit comments