Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
InsertionSort
#python 3.5.2 print ("Hello, world!") # sorted unsorted part # Example: [ 54 | {26}, 93, 17, 77, 31 ] # sorted unsorted # -------> [ 26, 54 | 93, 17, 77, 31 ] # -------> [ 26, 54, 93 | 17, 77, 31 ] # -------> [ 17, 26, 54, 93 | 77, 31 ] # Idea: Split the list into 2 parts - sorted and unsorted part # Take the first element in "unsorted part" and # Analyze its location in the "sorted part" # Hints: 1 outer for loop (for picking the first element in unsorted) # and inside 1 inner while loop (sorting analysis) def Insertionsort(alist): length = len(alist) for a in range(0,length): for i in range (0,a): a[0]=0 while a[0]<a[i]: if a[0]>a[i]: temp=a[0] a[0]=a[i] a[i]=temp return alist = [26,54,93,17,77,31] # length = 6 sortList = Insertionsort(alist) print (sortList)
run
|
edit
|
history
|
help
0
python decorator with parameter example
Python: Functions I : Functions with messages.
Lesson 9
models
arjun chinese class
calculate the sum of string 201test70de88qa ( only numbers)
wrong update class
Search for sum of pairs in given array
pytest
PyTypeClass