mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
The time complexity of every algorithms make its value (#1401)
* added timer in bubble sort * Updated time of execution * import time in main only * Update bubble_sort.py * start = time.process_time()
This commit is contained in:
parent
cd10c944d1
commit
38d7e7073a
@ -6,13 +6,13 @@ def bubble_sort(collection):
|
|||||||
:return: the same collection ordered by ascending
|
:return: the same collection ordered by ascending
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> bubble_sort([0, 5, 3, 2, 2])
|
>>> bubble_sort([0, 5, 2, 3, 2])
|
||||||
[0, 2, 2, 3, 5]
|
[0, 2, 2, 3, 5]
|
||||||
|
|
||||||
>>> bubble_sort([])
|
>>> bubble_sort([])
|
||||||
[]
|
[]
|
||||||
|
|
||||||
>>> bubble_sort([-2, -5, -45])
|
>>> bubble_sort([-2, -45, -5])
|
||||||
[-45, -5, -2]
|
[-45, -5, -2]
|
||||||
|
|
||||||
>>> bubble_sort([-23, 0, 6, -4, 34])
|
>>> bubble_sort([-23, 0, 6, -4, 34])
|
||||||
@ -34,6 +34,9 @@ def bubble_sort(collection):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
import time
|
||||||
user_input = input("Enter numbers separated by a comma:").strip()
|
user_input = input("Enter numbers separated by a comma:").strip()
|
||||||
unsorted = [int(item) for item in user_input.split(",")]
|
unsorted = [int(item) for item in user_input.split(",")]
|
||||||
|
start = time.process_time()
|
||||||
print(*bubble_sort(unsorted), sep=",")
|
print(*bubble_sort(unsorted), sep=",")
|
||||||
|
print(f"Processing time: {time.process_time() - start}")
|
||||||
|
Loading…
Reference in New Issue
Block a user