Skip to content

не понятно#146

Open
KirillLazarev wants to merge 1 commit into
mainfrom
KLazarev
Open

не понятно#146
KirillLazarev wants to merge 1 commit into
mainfrom
KLazarev

Conversation

@KirillLazarev
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Owner

@IlyaOrlov IlyaOrlov left a comment

Choose a reason for hiding this comment

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

Добавил комментарии по HW5.1.py
Для лучшего понимания стоит пройти алгоритм пошагово в режиме отладчика.

Comment thread Practice/Lazarev/HW5.1.py
@@ -0,0 +1,23 @@
# Реализовать алгоритм сортировки от мин к макс
def mini(s): # функц поиск минимального значения
min_num = float('inf') # минимальное значение почему-то +бесконечность?!
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.

Изначально, пока мы не начали смотреть строку, у нас нет какого-либо минимального значения. А сравнивать items уже с чем-то надо (стр.6).
+бесконечность - значение, больше которого заведомо не будет - при первом же сравнении заменится на начальный элемент в s.

Comment thread Practice/Lazarev/HW5.1.py
def sort_min(x): # функция сортировки
i = 0
while i < len(x):
min_idx, min_num = mini(x[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.

Потому что список x до i уже отсортирован и содержит минимальные значения.

Comment thread Practice/Lazarev/HW5.1.py
while i < len(x):
min_idx, min_num = mini(x[i:]) # почему функц мини накидываем на срез?
if min_idx != 0:
x[i], x[min_idx + i] = x[min_idx + i], x[i] # какое 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.

min_idx - это относительный индекс в срезе.
Чтоб получить корректный индекс, надо добавить к min_idx индекс начала среза - i.

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