Skip to content

hw6: Сортированный список#6

Open
DolzhenkoAlexa wants to merge 12 commits intomainfrom
HW6_Dolzhenko_sortList
Open

hw6: Сортированный список#6
DolzhenkoAlexa wants to merge 12 commits intomainfrom
HW6_Dolzhenko_sortList

Conversation

@DolzhenkoAlexa
Copy link
Owner

@DolzhenkoAlexa DolzhenkoAlexa commented Nov 19, 2025

Файлы: основной sortList.c и заголовочный sortList.h, а также interactiveMain.c для взаимодействия с пользователем (выделен в отдельный файл для удобства будущего написания тестов)

CMake также был отредактирован для новой версии сборки

Выполнено: Долженко Александра

// Так как список отсортирован, то прошлый будет или больше или равен вставляемому
while (currNode && currNode->data < element) {
currNode = currNode->next;
position++;

Choose a reason for hiding this comment

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

Почему бы не сразу здесь не вставить элемент? Ведь, чтобы вставить его по индексу, надо снова пробежать весь список.
Вообще, не очень понятно, почему Вас во всех задачах так тянет обращаться к элементам связного списка исключительно по индексу. Это же его слабая сторона. Вот например, в C++ библиотечный связный список не поддерживает оращение по индексу. Или ещё по какому-то признаку. Можно только честно дойти от начала до нужного элемента.

Copy link
Owner Author

Choose a reason for hiding this comment

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

думаю, это идет из-за привычки из питона, простите, буду стараться исправиться!


while (currNode) {
if (currNode->data == element) {
return position;

Choose a reason for hiding this comment

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

Снова, найденный элемент надо сразу удалять. Это и эффективнее, и проще, чем Ваша реализация.

// Created by sasha on 19.11.2025.
//

#ifndef SORTLIST_MAIN_H

Choose a reason for hiding this comment

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

По стайлгайду надо использовать pragma once, а не include guards.

Comment on lines 6 to 7
include_directories(src/hw6_sortList)
add_executable(sortList src/hw6_sortList/sortList.c)

Choose a reason for hiding this comment

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

И здесь тоже не соберётся

@DolzhenkoAlexa DolzhenkoAlexa mentioned this pull request Dec 21, 2025
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