Skip to content

Comments

Add cyclic list and counting task#11

Open
fleron19 wants to merge 2 commits intomasterfrom
counting
Open

Add cyclic list and counting task#11
fleron19 wants to merge 2 commits intomasterfrom
counting

Conversation

@fleron19
Copy link
Owner

No description provided.

@fleron19 fleron19 requested a review from WoWaster October 28, 2025 21:31
Comment on lines +6 to +13
CyclicList* newCyclicList(void);
void pushElement(CyclicList* list, int value);
int deleteIndex(CyclicList* list, unsigned value);
int getElement(CyclicList* list, unsigned value);
bool isEmpty(CyclicList* list);
void deleteCyclicList(CyclicList* list);
struct CyclicListNode* lastCyclicListNode(CyclicList* list);
int lengthCyclicList(CyclicList* list);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Хорошо бы иметь комментарии к функциям

int getElement(CyclicList* list, unsigned value);
bool isEmpty(CyclicList* list);
void deleteCyclicList(CyclicList* list);
struct CyclicListNode* lastCyclicListNode(CyclicList* list);
Copy link
Collaborator

Choose a reason for hiding this comment

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

А эта функция вообще используется? Да и кажется, что пользователю вообще нужно знать о внутреннем устройстве списка.

Comment on lines +8 to +9
int deleteIndex(CyclicList* list, unsigned value);
int getElement(CyclicList* list, unsigned value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

По-моему это не value, а index

free(list);
}

int deleteIndex(CyclicList* list, unsigned index) // deletenig by index instead of value, 1 - correct delition, 0 - incorrect
Copy link
Collaborator

Choose a reason for hiding this comment

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

Так может просто bool вернуть?

Comment on lines +26 to +33
if (isEmpty(list)) {
node->next = node;
list->head = node;
} else {
node->next = list->head->next;
list->head->next = node;
list->head = node;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Может я чего-то не понимаю, но по-моему Вы вставляете либо в голову, если там пусто, либо сразу после первого элемента и какой-то цикличности я не наблюдаю...

current = nextNode;
}
free(list->head);
list->head = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Мне кажется, это не нужно

struct CyclicListNode* prevNode = NULL;
struct CyclicListNode* currNode = list->head;
for (unsigned i = 0; i <= index; ++i) {
if (currNode) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

А правда ли в циклическом списке есть шанс, что у Вас currNode будет NULL при непустом списке?

}
return currNode->value;
} else {
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ну и вообще -1 такой себе код ошибки в данной задаче, с учётом того, что Вы храните int.

int getElement(CyclicList* list, unsigned index)
{
if (!isEmpty(list)) {
struct CyclicListNode* prevNode = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не используется?

Copy link
Collaborator

Choose a reason for hiding this comment

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

На входе 5 2 ответ должен быть 3, а у Вас здесь что-то не то :(

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