-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.py
More file actions
61 lines (49 loc) · 1.68 KB
/
Copy pathSelectionSort.py
File metadata and controls
61 lines (49 loc) · 1.68 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
def selectionSort(inputArray):
length = len(inputArray)
currentIndex = 0
while currentIndex < (length-1):
minindex = currentIndex
min = inputArray[currentIndex]
for i in range(currentIndex, length):
if (inputArray[i] < min):
minindex = i
min = inputArray[i]
inputArray[minindex] = inputArray[currentIndex]
inputArray[currentIndex] = min
currentIndex += 1
return inputArray
def selection_sort_by_heuristic(inputArray):
length = len(inputArray)
currentIndex = 0
while currentIndex < (length-1):
minindex = currentIndex
min = inputArray[currentIndex].heuristic()
for i in range(currentIndex, length):
if (inputArray[i].heuristic() < min):
minindex = i
min = inputArray[i].heuristic()
temp = inputArray[minindex]
inputArray[minindex] = inputArray[currentIndex]
inputArray[currentIndex] = temp
currentIndex += 1
a = []
for i in range(8):
a.append(inputArray[i].heuristic())
#print a
return inputArray
def selection_sort_by_func(inputArray, comparefunc):
length = len(inputArray)
currentIndex = 0
while currentIndex < (length-1):
minindex = currentIndex
min = comparefunc(inputArray[currentIndex])
for i in range(currentIndex, length):
thish = comparefunc(inputArray[i])
if (thish < min):
minindex = i
min = thish
temp = inputArray[minindex]
inputArray[minindex] = inputArray[currentIndex]
inputArray[currentIndex] = temp
currentIndex += 1
return inputArray