straight insertation algorithm in python

Solutions on MaxInterview for straight insertation algorithm in python by the best coders in the world

showing results for - "straight insertation algorithm in python"
Lisa
25 Apr 2017
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Created on Sun Mar 10 17:13:56 2019
5
6@note: Insertion sort algorithm
7@source: http://interactivepython.org/courselib/static/pythonds/SortSearch/TheInsertionSort.html
8
9"""
10
11def insertionSort(alist):
12   for index in range(1,len(alist)):
13
14     currentvalue = alist[index]
15     position = index
16
17     while position>0 and alist[position-1]>currentvalue:
18         alist[position]=alist[position-1]
19         position = position-1
20
21     alist[position]=currentvalue
22
similar questions
queries leading to this page
straight insertation algorithm in python