Skip to content

Comments

HW7 sortedList#31

Open
Andrw-404 wants to merge 14 commits intomainfrom
hw7-sortedList
Open

HW7 sortedList#31
Andrw-404 wants to merge 14 commits intomainfrom
hw7-sortedList

Conversation

@Andrw-404
Copy link
Owner

No description provided.

@@ -0,0 +1,161 @@
#include "list.h"

Choose a reason for hiding this comment

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

Кажется, это тут не нужно, у sortedList есть своя копия списка


#include <stdbool.h>

//test for a function that adds an item to a sorted list

Choose a reason for hiding this comment

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

Надо пробел после //

#include <stdio.h>

int main(void) {
setlocale(LC_ALL, "Rus");

Choose a reason for hiding this comment

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

Не используйте табуляции для отступов, и тем более не мешайте разные стили отступов в одном проекте

if (list == NULL) {
return NULL;
}
list->head = calloc(1, sizeof(ListElement));

Choose a reason for hiding this comment

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

Для сортированного списка стражник не нужен, потому что у него нет вставки по позиции


Value getValue(List* list, Position position) {
if (position == NULL) {
return (Value)0;

Choose a reason for hiding this comment

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

По-хорошему тут надо тоже error reporting, потому что 0 неотличим от валидного значения

return;
}
ListElement* element = malloc(sizeof(ListElement));
element->value = value;

Choose a reason for hiding this comment

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

Надо проверять успешность malloc

free(current);
current = next;
}
free(first(list));

Choose a reason for hiding this comment

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

Suggested change
free(first(list));
free(list->head);

Внутри модуля такие условности несколько избыточны

}

if (current->next == NULL) {
printf("\n!!!Такой элемент не найден\n");

Choose a reason for hiding this comment

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

Не общайтесь с пользователем вне main

List* list = createList();
addLast(list, 10);
if (isEmpty(list) || getValue(list, getPositionByNumber(list, 1)) != 10) {
return false;

Choose a reason for hiding this comment

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

А тут тоже надо список удалить

addElements(-19, listForAddTest);
addElements(4, listForAddTest);
if (isEmpty(listForAddTest)) {
return false;

Choose a reason for hiding this comment

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

И тут и в аналогичных ситуациях ниже. Список может быть пуст, когда у него есть и сама структура "Список" и стражник в голове, их ведь тоже удалить надо.

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