-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnumberSort.py
More file actions
71 lines (50 loc) · 1.84 KB
/
Copy pathnumberSort.py
File metadata and controls
71 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
##
# Program to accept and sort numbers in a list, aswell as measure how long it took
#
# Author: XCC
# Date: 10/25/2020
from libs import algorithms
import timeit
# Initialize list variable
numList = []
done = False
# Loop until user is satisfied
while(not done):
numInput = input(
"Enter a number to add to the list, if you wish to stop adding numbers enter 'q': \n")
# Quit out of loop when user says to
if numInput == 'q':
done = True
break
# Try except to catch ValueError when converting string input to int
try:
numList.append(int(numInput))
except:
print("Please enter a single number")
### Output the list sorted with various algoritms ###
# To compare, output the unsorted list
print("Unsorted list:" + str(numList))
## Bubble sort ##
# Output sorted
print("Sorted with bubble sort" + str(algorithms.bubbleSort(numList)))
# Time the sorting with timeit.timeit
time = timeit.timeit('algorithms.bubbleSort(numList)',
'from __main__ import algorithms, numList')
# Output the time it took in micro seconds
print("Time: " + str(time) + " micro sec")
## Insertion sort ##
# Output sorted
print("Sorted with insertion sort" + str(algorithms.insertionSort(numList)))
# Time the sorting with timeit.timeit
time = timeit.timeit('algorithms.insertionSort(numList)',
'from __main__ import algorithms, numList')
# Output the time it took in micro seconds
print("Time: " + str(time) + " micro sec")
## Selection sort ##
# Output sorted
print("Sorted with selection sort" + str(algorithms.selectionSort(numList)))
# Time the sorting with timeit.timeit
time = timeit.timeit('algorithms.selectionSort(numList)',
'from __main__ import algorithms, numList')
# Output the time it took in micro seconds
print("Time: " + str(time) + " micro sec")