Skip to content

Comments

вторая контрольная работа по си#30

Open
Gosha924 wants to merge 1 commit intomasterfrom
second_kr_c
Open

вторая контрольная работа по си#30
Gosha924 wants to merge 1 commit intomasterfrom
second_kr_c

Conversation

@Gosha924
Copy link
Owner

@Gosha924 Gosha924 commented Dec 5, 2025

q

Copy link
Collaborator

@p-senichenkov p-senichenkov left a comment

Choose a reason for hiding this comment

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

18/20 (за неоптимальное решение и стайлгайд)

int finish = getValue(numbers, j);
if (start != finish) {
// printf("NOT palindrom\n");
isPalindrom--;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Никогда так не делайте.

Suggested change
isPalindrom--;
isPalindrom = 0;

А лучше, #include <stdbool.h> и

Suggested change
isPalindrom--;
isPalindrom = false;

Comment on lines +76 to +80
for (int i = 0; i < len; i++) {
printf("Введите число\n");
scanf("%d", &value);
insertNum(numbers, value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

В такой реализации этот цикл имеет квадратичную сложность. А можно довольно легко получить линейную. Подумайте, как.

Если ничего не придумается, посмотрите на https://en.cppreference.com/w/cpp/container/forward_list/insert_after.html.

Comment on lines +10 to +11
int start = getValue(numbers, i);
int finish = getValue(numbers, j);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если вдруг понадобилось обращаться по индексу в связном списке, скорее всего, Вам нужен динамический массив, а не список. А здесь можно можно начать с первого элемента и переходить по next. Правда, для этого понадобится двусвязный список, но его реализовать так же легко, как и односвязный.

Понятно, что такая реализация проще (особенно, если Вы скопировали список из одной из предыдущих домашек), но она сильно проигрывает оптимальной в эффективности.

@@ -0,0 +1,21 @@
#ifndef LIST_H
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

И всё остальное тоже отформатируйте. Вообще, надо настроить clang-format в CI, чтобы он автоматически всё проверял.

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