Line 21: |
Line 21: |
| ---- | | ---- |
| | | |
− | {|
| |
− | |+ Python Insertion Sort Example 1
| |
− | |-
| |
− | |def insertionSort(alist):
| |
− | | :for index in range(1,len(alist)):
| |
− | | : :currentvalue = alist[index]
| |
− | | : :position = index
| |
− | | : :while position>0 and alist[position-1]>currentvalue:
| |
− | | : : :alist[position]=alist[position-1]
| |
− | | : : :position = position-1
| |
− | | : :alist[position]=currentvalue
| |
| | | |
− | |alist = [54,26,93,17,77,31,44,55,20]
| + | Python Insertion Sort Example 1 |
− | |insertionSort(alist)
| + | |
− | |print(alist)
| + | <syntaxhighlight lang="cpp"> |
− | |}
| + | def insertionSort(alist): |
| + | :for index in range(1,len(alist)): |
| + | : :currentvalue = alist[index] |
| + | : :position = index |
| + | : :while position>0 and alist[position-1]>currentvalue: |
| + | : : :alist[position]=alist[position-1] |
| + | : : :position = position-1 |
| + | : :alist[position]=currentvalue |
| + | |
| + | alist = [54,26,93,17,77,31,44,55,20] |
| + | insertionSort(alist) |
| + | print(alist) |
| + | </syntaxhighlight> |
| + | |
| === Which Algorithms Are Best Suited for Which Tasks === | | === Which Algorithms Are Best Suited for Which Tasks === |
| | | |