0% found this document useful (0 votes)
14 views2 pages

Python Insertion Sort Example

The document discusses insertion sorting of a sample list of numbers. It includes the original unsorted list, defines an insertion sort function, and prints the sorted list after applying the function.

Uploaded by

23412047
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Python Insertion Sort Example

The document discusses insertion sorting of a sample list of numbers. It includes the original unsorted list, defines an insertion sort function, and prints the sorted list after applying the function.

Uploaded by

23412047
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Afn

the lit

ton t,w

tRsse alomen.
lemt (i++) anod
Meue to te neset

serted.
main.py Save Run Shell Clear

1 python program to do insertion sorting or ignal list: [10, 15, 41, 2, 25]
2 sortedlíst; (2, 10, 15, 25, 41]
3. def insertion_sor t(arr ):
for i in range(1,len(arr)):
5 key arr[i]
6 j-i-1
7: while j>=0 and key <arril:
8
arr(j"1]-arr[j]
9 j--1
arr[j+1]-key
11
12 mylist=[10,15,41 ,2,25]
3 print("orignal list:",mylist)
4 insertion_sort (myl ist)
15 print("sor tedlist;",mylíst)

You might also like