Skip to content

TD Tri - Nathan Deroche#33

Open
NanaNana64 wants to merge 2 commits intobcalou:mainfrom
NanaNana64:main
Open

TD Tri - Nathan Deroche#33
NanaNana64 wants to merge 2 commits intobcalou:mainfrom
NanaNana64:main

Conversation

@NanaNana64
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
Owner

@bcalou bcalou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extrême similarité avec le code de Timothée, même dans les imperfections. S'entraider est différent de copier/coller, et on s'en rend compte très vite en corrigeant.

@NanaNana64
Copy link
Copy Markdown
Author

Extrême similarité avec le code de Timothée, même dans les imperfections. S'entraider est différent de copier/coller, et on s'en rend compte très vite en corrigeant.

Moi et timothée n'avons pas travaillé sur ce TD ensemble ni même ne nous sommes entraidés, les similarités sont donc fortuites.

Copy link
Copy Markdown
Owner

@bcalou bcalou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien

:return: sorted array
"""
for i in range(1, len(array)):
key = array[i]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi key ?

Comment on lines +11 to +13
while j >= 0 and key < array[j]:
array[j + 1] = array[j]
j -= 1
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu modifies le tableau à chaque itération. On peut le modifier une seule fois, après avoir trouvé le bon index.

Comment on lines +8 to +11
if number == 0:
return 1
else:
return number * get_factorial(number - 1)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ternaire ?

Comment on lines +8 to +14
for i in range(len(array)):
min_index = i
for j in range(i + 1, len(array)):
if array[min_index] > array[j]:
min_index = j

array[i], array[min_index] = array[min_index], array[i]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quelques commentaires pour mieux suivre la logique ?

@bcalou
Copy link
Copy Markdown
Owner

bcalou commented Dec 5, 2023

Réponses claires au TP. Code très clair avec beaucoup d'attention à la lisibilité.
Dommage, dans le tri par insertion, la dernière boucle for est inutile : on pourrait directement insérer l'élément à la place voulue, pas besoin de déplacer un par un.
Mais très bien.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants