Changes

Jump to navigation Jump to search
49 bytes added ,  17:41, 13 December 2016
no edit summary
Line 22: Line 22:     
{|
 
{|
def insertionSort(alist):
+
|+ Python Insertion Sort Example 1
:for index in range(1,len(alist)):
+
|-
: :currentvalue = alist[index]
+
|def insertionSort(alist):
: :position = index
+
| :for index in range(1,len(alist)):
: :while position>0 and alist[position-1]>currentvalue:
+
| : :currentvalue = alist[index]
: : :alist[position]=alist[position-1]
+
| : :position = index
: : :position = position-1
+
| : :while position>0 and alist[position-1]>currentvalue:
: :alist[position]=currentvalue
+
| : : :alist[position]=alist[position-1]
 +
| : : :position = position-1
 +
| : :alist[position]=currentvalue
   −
alist = [54,26,93,17,77,31,44,55,20]
+
|alist = [54,26,93,17,77,31,44,55,20]
insertionSort(alist)
+
|insertionSort(alist)
print(alist)  
+
|print(alist)  
 
|}
 
|}
 
=== Which Algorithms Are Best Suited for Which Tasks ===
 
=== Which Algorithms Are Best Suited for Which Tasks ===
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu