python - Is that Insertionsort? -


i need help, learning sorting-algorithms , tried make insertionsort-algorithm. please tell me whether insertionsort-algorithm or not?

def insertsort(l):     k in range(len(l)):         in range(1,len(l)):             if l[i]<l[i-1]:                 while l[i]<l[i-1]:                     l.insert(i-1,l.pop(i))     return l 

yes, insertion sort. pseudocode follows:

1.      j = 2 n 2.           key ← [j] 3.          // insert a[j] sorted sequence a[1..j-1] 4.           j ← – 1 5.         while > 0 , a[i] > key 6.                  a[i+1] ← a[i] 7.                  ← – 1 8.          a[j+1] ← key 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -