AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Insertion sort - Python algorithm

Go down

Insertion sort - Python algorithm

Post by Lucaci Andrei on Mon Feb 13, 2012 5:41 am

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
def ins(h):
for i in range(1, len(h)):
p = h[i]
j = i
while j > 0 and h[j - 1] > p:
h[j] = h[j - 1]
j -= 1
h[j] = p


l = [9, 3, 1, 2, 3, 1, 2, 3]
print l
ins(l)
print l

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum