-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind-smallest.py
More file actions
33 lines (28 loc) · 785 Bytes
/
find-smallest.py
File metadata and controls
33 lines (28 loc) · 785 Bytes
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
import time
t0 = time.time()
# Declare array to sort
arrToSort = [2323, 4,232,44,44, 2]
# Function to find smallest value
def findSmallest(array):
# Assumes smallest value is first item
smallest = array[0]
index = 0
# Loops through each item in the array starting at position 1
for i in range(1, len(array)):
if array[i] < smallest:
smallest = array[i]
index = i
return index
# Create Selection Sort Function
def selSort(arr):
newSortedArray = []
for val in range(len(arr)):
smallVal = findSmallest(arr)
newSortedArray.append(arr.pop(smallVal))
return newSortedArray
t1 = time.time()
total = t0 + t1
# Output to the screen
print(selSort(arrToSort))
# Prints total time
print "Total Time:", total