Skip to content

Comments

Сортированный список. Кальсина Яна. Б43.#18

Open
yaprogrammer18-yanchi wants to merge 6 commits intomainfrom
branch_for_lists_homework2
Open

Сортированный список. Кальсина Яна. Б43.#18
yaprogrammer18-yanchi wants to merge 6 commits intomainfrom
branch_for_lists_homework2

Conversation

@yaprogrammer18-yanchi
Copy link
Owner

Добавила все файлы для задачи "Сортированный список" в том числе и Cmake.

Copy link

@ilya-krivtsov ilya-krivtsov left a comment

Choose a reason for hiding this comment

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

В целом хорошо, в паре мест просто добавить проверку того, что память действительно выделилась

@@ -0,0 +1,117 @@
#include "OneLinkedList.h"

Choose a reason for hiding this comment

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

list.h вполне нормальное название, но ладно

Comment on lines +6 to +11
typedef struct ListNode ListNode;

struct ListNode {
int value;
struct ListNode* next;
};

Choose a reason for hiding this comment

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

это то же самое, что и

Suggested change
typedef struct ListNode ListNode;
struct ListNode {
int value;
struct ListNode* next;
};
typedef struct ListNode {
int value;
struct ListNode* next;
} ListNode;

но так тоже можно


List* newList()
{
List* list = calloc(1, sizeof(*list));

Choose a reason for hiding this comment

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

Так можно, но лучше (как мне кажется) аллоцировать как угодно (malloc/calloc), и явно проинициализировать поля

return list;
}

bool isEmpty(List* list) { return list->head == NULL; }

Choose a reason for hiding this comment

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

Желательно чтобы все методы были в одном стиле

Suggested change
bool isEmpty(List* list) { return list->head == NULL; }
bool isEmpty(List* list) {
return list->head == NULL;
}

if (list == NULL) {
return false;
}
ListNode* newNode = malloc(sizeof(ListNode));

Choose a reason for hiding this comment

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

Нужно сделать проверку, что память действительно выделилась

Comment on lines +7 to +12
/*
* функция создания нового списка
* ничего не принимает
* возвращает указатель на список
*/
List* newList();

Choose a reason for hiding this comment

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

Если функция ничего не принимает, то это сразу видно и можно не писать в комментарии :)

Comment on lines +91 to +93
if (list == NULL) {
return false;
}

Choose a reason for hiding this comment

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

Вообще free(NULL) - вполне нормальная операция, поэтому можно разрешить и то, что list - NULL, но так тоже можно

Comment on lines +16 to +17
int c;
while ((c = getchar()) != '\n') { }

Choose a reason for hiding this comment

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

Можно просто

Suggested change
int c;
while ((c = getchar()) != '\n') { }
while (getchar() != '\n') { }

return;
}
clearInputBuffer();
insert(list, element);

Choose a reason for hiding this comment

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

insert возвращает bool, значит надо его проверить

if (removeElement(list, value)) {
printf("Элемент успешно удален.\n");
} else {
printf("Что-то пошло не так. Возможно введено неверное значение.\n");

Choose a reason for hiding this comment

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

Тут скорее стоит написать, что значения нет в списке, потому что false возвращается если список - NULL (а такого почти никогда не происходит), список пустой или элемент не найден; пустой список => никакого элемента в нём не найти

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