Algorisme d'ordenació pel mètode de la inserció

De binefa.com
Salta a la navegació Salta a la cerca

Algorisme

Algorisme d'ordenació pel mètode de la inserció

(font)

Algorisme d'ordenació pel mètode de la inserció

(font)

a = [1,4,8,9,11,15,7,12,13,6]
visualitzaLlista(a)
a = ordenaInsercio(a)
visualitzaLlista(a)
1 4 8 9 11 15 7 12 13 6 
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6]  ,  1  ,  4  )
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6]  ,  2  ,  8  )
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6]  ,  3  ,  9  )
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6]  ,  4  ,  11  )
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6]  ,  5  ,  15  )
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6]  ,  6  ,  7  )
inserta( [1, 4, 7, 8, 9, 11, 15, 12, 13, 6]  ,  7  ,  12  )
inserta( [1, 4, 7, 8, 9, 11, 12, 15, 13, 6]  ,  8  ,  13  )
inserta( [1, 4, 7, 8, 9, 11, 12, 13, 15, 6]  ,  9  ,  6  )
1 4 6 7 8 9 11 12 13 15
Algorisme d'ordenació pel mètode de la inserció

(font)

a = [15,9,8,1,4,11,7,12,13,6,5,3,16,2,10,14]
visualitzaLlista(a)
a = ordenaInsercio(a)
visualitzaLlista(a)
15 9 8 1 4 11 7 12 13 6 5 3 16 2 10 14 
inserta( [15, 9, 8, 1, 4, 11, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  1  ,  9  )
inserta( [9, 15, 8, 1, 4, 11, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  2  ,  8  )
inserta( [8, 9, 15, 1, 4, 11, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  3  ,  1  )
inserta( [1, 8, 9, 15, 4, 11, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  4  ,  4  )
inserta( [1, 4, 8, 9, 15, 11, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  5  ,  11  )
inserta( [1, 4, 8, 9, 11, 15, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  6  ,  7  )
inserta( [1, 4, 7, 8, 9, 11, 15, 12, 13, 6, 5, 3, 16, 2, 10, 14]  ,  7  ,  12  )
inserta( [1, 4, 7, 8, 9, 11, 12, 15, 13, 6, 5, 3, 16, 2, 10, 14]  ,  8  ,  13  )
inserta( [1, 4, 7, 8, 9, 11, 12, 13, 15, 6, 5, 3, 16, 2, 10, 14]  ,  9  ,  6  )
inserta( [1, 4, 6, 7, 8, 9, 11, 12, 13, 15, 5, 3, 16, 2, 10, 14]  ,  10  ,  5  )
inserta( [1, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 3, 16, 2, 10, 14]  ,  11  ,  3  )
inserta( [1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 16, 2, 10, 14]  ,  12  ,  16  )
inserta( [1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 16, 2, 10, 14]  ,  13  ,  2  )
inserta( [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 16, 10, 14]  ,  14  ,  10  )
inserta( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 14]  ,  15  ,  14  )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

a = [1,4,8,9,11,15,7,12,13,6]
print(a)
del a[1]
print(a)
a.insert(2,33)
print(a)
[1, 4, 8, 9, 11, 15, 7, 12, 13, 6]
[1, 8, 9, 11, 15, 7, 12, 13, 6]
[1, 8, 33, 9, 11, 15, 7, 12, 13, 6]