Skip to content

Théo Thénault - TP Algo tri #34

Open
TheoThenault wants to merge 19 commits into
bcalou:mainfrom
TheoThenault:main
Open

Théo Thénault - TP Algo tri #34
TheoThenault wants to merge 19 commits into
bcalou:mainfrom
TheoThenault:main

Conversation

@TheoThenault

Copy link
Copy Markdown

No description provided.

@bcalou bcalou left a comment

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.

Bien

Comment thread sort/selection.py Outdated
Comment on lines +15 to +16
smallest_number: int = array[number_of_sorted_numbers]
smallest_number_index: int = number_of_sorted_numbers

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 ne pas stocker uniquement l'index ? Le code sera un peu plus simple

Comment thread sort/insertion.py Outdated
for index in range(1, len(array)):
number: int = array[index]
# on parcours la partie trié du tableau dans le sens décroissant
for sorted_numberIndex in reversed(range(0, number_of_sorted_numbers)):

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.

rester en snake_case

Comment thread sort/insertion.py Outdated
Comment on lines +25 to +28
if number < sorted_number:
array.insert(sorted_numberIndex, number)
else:
array.insert(sorted_numberIndex+1, number)

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.

Ça marche mais ce n'est pas tout à fait satisfaisant, ce +1 conditionnel. Trouver une autre approche ? Je pinaille...

Comment thread sort/fusion.py Outdated
Comment on lines +33 to +36
# Le deuxième tableau peut être vide si le tableau original
# a une taille impaire
if array2 == []:
return array1

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.

En es-tu sûr ? Pas d'après ce que je lis dans sort.

Comment thread sort/fusion.py Outdated
Comment on lines +49 to +56
if index1 >= size1 and index2 < size2:
sorted_array.append(array2[index2])
index2 += 1
continue
elif index2 >= size2 and index1 < size1:
sorted_array.append(array1[index1])
index1 += 1
continue

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.

Ça marche mais ça veut dire qu'on va ajouter tous les éléments restant un par un, itération après itération. On ne peut pas faire plus direct ?

@bcalou

bcalou commented Dec 5, 2023

Copy link
Copy Markdown
Owner

C'est très bien, avec un bémol cette fois-ci sur la quantité de commentaires : il faut tout à fait en mettre, mais attention à ne pas noyer le code non plus et à rester pertinent. C'est un équilibre à trouver. Si le code se suffit à lui-même, on peut parfois en retier un peu.
Quelques petites optimisations possibles mais c'est très clair et bien structuré.

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