-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInsertionSort.py
More file actions
28 lines (24 loc) · 923 Bytes
/
InsertionSort.py
File metadata and controls
28 lines (24 loc) · 923 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
import Jobs
def insertionSort(alist):
jobs = []
for index in range(1,len(alist)):
jobs.append(Jobs.JobGoTo(index))
jobs.append(Jobs.JobPlaceTreasure(index))
currentvalue = alist[index]
position = index
while position > 0 and alist[position-1]>currentvalue:
jobs.append(Jobs.JobGoTo(index))
jobs.append(Jobs.JobPickUpTreasure(index))
jobs.append(Jobs.JobStoreTreasure())
alist[position]=alist[position-1]
jobs.append(Jobs.JobGoTo(index+1))
jobs.append(Jobs.JobPickUpTreasure(index+1))
jobs.append(Jobs.JobGoTo(index))
jobs.append(Jobs.JobPlaceTreasure(index))
alist[position] = currentvalue
jobs.append(Jobs.JobGoTo(index+1))
jobs.append(Jobs.JobSwapHandWithContainer())
jobs.append(Jobs.JobPlaceTreasure(index+1))
position = position-1
jobs.append(Jobs.JobIdle())
return Jobs