Conversation
| 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); |
There was a problem hiding this comment.
Хорошо бы иметь комментарии к функциям
| int getElement(CyclicList* list, unsigned value); | ||
| bool isEmpty(CyclicList* list); | ||
| void deleteCyclicList(CyclicList* list); | ||
| struct CyclicListNode* lastCyclicListNode(CyclicList* list); |
There was a problem hiding this comment.
А эта функция вообще используется? Да и кажется, что пользователю вообще нужно знать о внутреннем устройстве списка.
| int deleteIndex(CyclicList* list, unsigned value); | ||
| int getElement(CyclicList* list, unsigned value); |
There was a problem hiding this comment.
По-моему это не value, а index
| free(list); | ||
| } | ||
|
|
||
| int deleteIndex(CyclicList* list, unsigned index) // deletenig by index instead of value, 1 - correct delition, 0 - incorrect |
There was a problem hiding this comment.
Так может просто bool вернуть?
| if (isEmpty(list)) { | ||
| node->next = node; | ||
| list->head = node; | ||
| } else { | ||
| node->next = list->head->next; | ||
| list->head->next = node; | ||
| list->head = node; | ||
| } |
There was a problem hiding this comment.
Может я чего-то не понимаю, но по-моему Вы вставляете либо в голову, если там пусто, либо сразу после первого элемента и какой-то цикличности я не наблюдаю...
| current = nextNode; | ||
| } | ||
| free(list->head); | ||
| list->head = NULL; |
There was a problem hiding this comment.
Мне кажется, это не нужно
| struct CyclicListNode* prevNode = NULL; | ||
| struct CyclicListNode* currNode = list->head; | ||
| for (unsigned i = 0; i <= index; ++i) { | ||
| if (currNode) { |
There was a problem hiding this comment.
А правда ли в циклическом списке есть шанс, что у Вас currNode будет NULL при непустом списке?
| } | ||
| return currNode->value; | ||
| } else { | ||
| return -1; |
There was a problem hiding this comment.
Ну и вообще -1 такой себе код ошибки в данной задаче, с учётом того, что Вы храните int.
| int getElement(CyclicList* list, unsigned index) | ||
| { | ||
| if (!isEmpty(list)) { | ||
| struct CyclicListNode* prevNode = NULL; |
There was a problem hiding this comment.
На входе 5 2 ответ должен быть 3, а у Вас здесь что-то не то :(
No description provided.