Diferència entre revisions de la pàgina «Algorisme d'ordenació pel mètode de la inserció»
Salta a la navegació
Salta a la cerca
(Es crea la pàgina amb «= Algorisme = center|Algorisme d'ordenació pel mètode de la inserció ([https://medium.com/austins-software-engineering-journey/insertion-so...».) |
m |
||
(Hi ha 3 revisions intermèdies del mateix usuari que no es mostren) | |||
Línia 20: | Línia 20: | ||
inserta( [1, 4, 7, 8, 9, 11, 12, 13, 15, 6] , 9 , 6 ) | inserta( [1, 4, 7, 8, 9, 11, 12, 13, 15, 6] , 9 , 6 ) | ||
1 4 6 7 8 9 11 12 13 15 | 1 4 6 7 8 9 11 12 13 15 | ||
+ | |||
+ | [[Image:Insercio03.png|center|Algorisme d'ordenació pel mètode de la inserció]] ([https://www.oreilly.com/library/view/algorithms-in-a/9780596516246/ch04s02.html 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] |
Revisió de 12:03, 3 abr 2024
Algorisme
(font)
(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
(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]