From f75e15ae21e631c29c8d52c0a77a142575660057 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Sat, 25 Oct 2025 23:33:50 +0300 Subject: [PATCH 1/8] Add all the files for homework about lists. They are all ready to be checked! --- src/listLesson/counting.c | 48 +++++++++ src/listLesson/cyclicList.c | 161 ++++++++++++++++++++++++++++++ src/listLesson/cyclicList.h | 79 +++++++++++++++ src/listLesson/list.c | 169 ++++++++++++++++++++++++++++++++ src/listLesson/list.h | 92 +++++++++++++++++ src/listLesson/sortedListTask.c | 55 +++++++++++ 6 files changed, 604 insertions(+) create mode 100644 src/listLesson/counting.c create mode 100644 src/listLesson/cyclicList.c create mode 100644 src/listLesson/cyclicList.h create mode 100644 src/listLesson/list.c create mode 100644 src/listLesson/list.h create mode 100644 src/listLesson/sortedListTask.c diff --git a/src/listLesson/counting.c b/src/listLesson/counting.c new file mode 100644 index 0000000..18f329c --- /dev/null +++ b/src/listLesson/counting.c @@ -0,0 +1,48 @@ +#include "cyclicList.h" +#include "list.h" +#include +#include +// решение через односвязный список +// знаю, что не по условию, но тоже как вариант реализации +int simpleListRealisation() { + printf("Введите n и m через пробел\n"); + int n = 0; + int m = 0; + scanf("%d %d", &n, &m); + List *list = newList(); + for (int i = 1; i <= n; i++) { + insert(list, i - 1, i); + } + int count = 1; + int index = 0; + while (!oneElement(list)) { + if ((count % m) == 0) { + removeElement(list, index); + // откатываем назад индекс + index--; + } + count++; + index++; + + if (index == getLength(list)) { + index = 0; + } + } + printList(list); + return 0; +} + +// решение через циклический список +int main() { + printf("Введите n и m через пробел\n"); + int n = 0; + int m = 0; + scanf("%d %d", &n, &m); + List *list = newList(); + for (int i = 1; i <= n; i++) { + insert(list, i - 1, i); + } + printf("%d", findTheSafeIndex(list, m)); + + return 0; +} diff --git a/src/listLesson/cyclicList.c b/src/listLesson/cyclicList.c new file mode 100644 index 0000000..97c2be0 --- /dev/null +++ b/src/listLesson/cyclicList.c @@ -0,0 +1,161 @@ +#include "cyclicList.h" +#include "stdio.h" +#include +#include + +typedef struct ListNode { + int value; + ListNode *next; + +} ListNode; + +typedef struct List { + ListNode *head; +} List; + +List *newList() { + List *new = calloc(1, sizeof(*new)); + return new; +} + +bool insert(List *list, int index, int value) { + if (list == NULL) { + return false; + } + if (isEmpty(list)) { + ListNode *newNode = calloc(1, sizeof(ListNode)); + newNode->value = value; + newNode->next = newNode; + list->head = newNode; + return true; + } + if (index == 0) { + ListNode *newNode = calloc(1, sizeof(ListNode)); + newNode->value = value; + ListNode *current = list->head; + while (current->next != list->head) { + current = current->next; + } + newNode->next = list->head; + list->head = newNode; + current->next = newNode; + return true; + } + + ListNode *current = list->head; + int counter = 0; + // условия для while нет, чтобы пользователь мог вставлять элемент на любой + // индекс (так как список цикличный, ему нет разницы какой индекс указали) + while (1) { + if (counter == index - 1) { + ListNode *newNode = calloc(1, sizeof(ListNode)); + newNode->value = value; + newNode->next = current->next; + current->next = newNode; + return true; + } + current = current->next; + counter++; + } + return false; +} + +bool removeElement(List *list, int index) { + if (list == NULL || isEmpty(list)) { + return false; + } + + if (index == 0) { + ListNode *elemToRemove = list->head; + if (elemToRemove->next == elemToRemove) { + free(elemToRemove); + list->head = NULL; + return true; + } + + ListNode *current = list->head; + while (current->next != elemToRemove) { + current = current->next; + } + list->head = elemToRemove->next; + current->next = list->head; + free(elemToRemove); + return true; + } + + ListNode *current = list->head; + int counter = 0; + // условия для while нет, чтобы пользователь мог вставлять элемент на любой + // индекс (так как список цикличный, ему нет разницы какой индекс указали) + while (1) { + if (counter == index - 1) { + ListNode *nodeToDelete = current->next; + current->next = nodeToDelete->next; + free(nodeToDelete); + return true; + } + current = current->next; + counter++; + } + return false; +} + +bool deleteList(List *list) { + if (list == NULL || isEmpty(list)) { + return false; + } + while (!isEmpty(list)) { + removeElement(list, 0); + } + free(list); + return true; +} + +bool isEmpty(List *list) { return list->head == NULL; } + +bool oneElement(List *list) { return list->head->next == list->head; } + +void printList(List *list) { + if (list == NULL || isEmpty(list)) { + printf("Список пустой\n"); + return; + } + ListNode *current = list->head; + do { + printf("%d ", current->value); + current = current->next; + } while (current != list->head); + printf("\n"); +} + +int getLength(List *list) { + if (list == NULL || isEmpty(list)) { + return -1; + } + int counter = 0; + ListNode *current = list->head; + do { + counter++; + current = current->next; + } while (current != list->head); + return counter; +} + +int findTheSafeIndex(List *list, int m) { + ListNode *current = list->head; + ListNode *prev = NULL; + while (!oneElement(list)) { + for (int i = 0; i < m; i++) { + prev = current; + current = current->next; + } + if (current == list->head) { + list->head = current->next; + } + + prev->next = current->next; + free(current); + current = prev->next; + } + return list->head->value; +} diff --git a/src/listLesson/cyclicList.h b/src/listLesson/cyclicList.h new file mode 100644 index 0000000..4660029 --- /dev/null +++ b/src/listLesson/cyclicList.h @@ -0,0 +1,79 @@ +#pragma once +#include + +// структура обычного элемента в списке +typedef struct ListNode ListNode; + +// структура содержащая указатель на первый элемент списка +typedef struct List List; + +/* + * функция создания нового списка + * ничего не принимает + * возвращает указатель на объект типа List + */ +List *newList(); + +/* + * функция вставки элемента по заданному индексу + * принимает на вход указатель на объект типа List, желаемый индекс и значение + * возвращает булевое значение, сообщающее, удачно ли прошла операция + */ +bool insert(List *list, int index, int value); + +/* + * функция удаления элемента по индексу + * принимает указатель на объект типа List и индекс элемента + * возвращает булевое значние, сообщающее, удачно ли прошла операция + * внутри себя освобождает память удаляемого элемента + */ +bool removeElement(List *list, int index); + +/* + * функция удаления всего списка + * принимает указатель на объект типа List + * внутри себя вызывает функцию removeElement + * возвращает булевое значение, удачно ли прошла операция + */ +bool deleteList(List *list); + +/* + * функция проверки, пустой ли список + * возвращает true если пустой, false, если нет + * на вход принимает указатель на список + */ +bool isEmpty(List *list); + +/* + * функция проверки, один ли элемент в списке + * возвращает true если да, false, если нет + * на вход принимает указатель на список + */ +bool oneElement(List *list); + +/* + * функция вывода списка в консоль + * принимает только указаетль на первый элемент списка, + * ничего не возвращает + * печатает элементы списка через пробел + * в случае переданного пустого или несуществующего списка сообщает об этом + * пользователю + */ +void printList(List *list); + +/* + * функция, возвращающая длину списка + * принимает на вход указатель на список + * проходится по всем элементам + * возвращает его длину + */ +int getLength(List *list); + +/* + * функция алгоритма Иосифа + * на вход принимает указатель на объект типа List и m (каждого m-того война + * будут убивать) возвращает значение последнего оставшегося элемента - места, + * куда нужно встать, по условию задачи функция создана исключительно для + * реализации алгоритма из файла counting.c. + */ +int findTheSafeIndex(List *list, int m); diff --git a/src/listLesson/list.c b/src/listLesson/list.c new file mode 100644 index 0000000..673ecde --- /dev/null +++ b/src/listLesson/list.c @@ -0,0 +1,169 @@ +#include "list.h" +#include +#include +#include +// структура обычного элемента в списке +struct ListNode { + int value; + struct ListNode *next; +}; + +// структура содержащая указатель на первый элемент списка +struct List { + ListNode *head; +}; + +List *newList() { + List *list = calloc(1, sizeof(*list)); + return list; +} + +bool insert(List *list, int index, int value) { + if (list == NULL || index < 0) { + return false; + } + if (index == 0) { + ListNode *newNode = malloc(sizeof(ListNode)); + newNode->value = value; + newNode->next = list->head; + list->head = newNode; + return true; + } + ListNode *current = list->head; + int counter = 0; + while (current != NULL) { + if (counter == index - 1) { + ListNode *newNode = malloc(sizeof(ListNode)); + newNode->value = value; + newNode->next = current->next; + current->next = newNode; + return true; + } + current = current->next; + counter++; + } + return false; +} +// а что если пользователь ошибся?? ввел не тот индекс например? что возвращать? +int get(List *list, int index) { + if (list == NULL || isEmpty(list) || index < 0) + return -1; + if (index == 0) { + return list->head->value; + } + ListNode *current = list->head; + int counter = 0; + while (current != NULL) { + if (counter == index) { + return current->value; + } + current = current->next; + counter++; + } + return -1; +} + +bool removeElement(List *list, int index) { + if (list == NULL || isEmpty(list) || index < 0) { + return false; + } + ListNode *current = list->head; + if (index == 0) { + list->head = current->next; + free(current); + return true; + } + int counter = 0; + while (current != NULL) { + if (counter == index - 1) { + if (current->next == NULL) + return false; + ListNode *nodeToDelete = current->next; + current->next = nodeToDelete->next; + free(nodeToDelete); + return true; + } + current = current->next; + counter++; + } + return false; +} + +bool deleteList(List *list) { + if (list == NULL || isEmpty(list)) { + return false; + } + while (!isEmpty(list)) { + removeElement(list, 0); + } + free(list); + return true; +} + +// надо указатель на втоорй список переделать на NULL и сообщить об этом +// пользователю там два указаеля надо тип ** +List *appendLists(List *list1, List *list2) { + ListNode *currentIn1 = list1->head; + while (currentIn1->next != NULL) { + currentIn1 = currentIn1->next; + } + currentIn1->next = list2->head; + return list1; +} + +void printList(List *list) { + if (list == NULL || isEmpty(list)) { + printf("Список пустой\n"); + return; + } + + ListNode *current = list->head; + while (current != NULL) { + printf("%d ", current->value); + current = current->next; + } + printf("\n"); +} + +bool isEmpty(List *list) { return list->head == NULL; } + +bool insert_sorted_in_ascending_order(List *list, int value) { + if (list == NULL) { + return false; + } + // случай еще незаполненного списка + if (isEmpty(list)) { + return insert(list, 0, value); + } + ListNode *current = list->head; + int counter = 0; + // если элемент самый маленький и его надо вставить в начало + if (current->value > value) { + return insert(list, 0, value); + } + while (current != NULL && current->next != NULL) { + if ((current->next->value > value) && (current->value <= value)) { + return (insert(list, counter + 1, value)); + } + current = current->next; + counter++; + } + // если программа достигла этой строчки, то значит что элемент больше всех + // остальных + return insert(list, counter + 1, value); +} + +int getLength(List *list) { + if (list == NULL || isEmpty(list)) { + return -1; + } + int counter = 0; + ListNode *current = list->head; + do { + counter++; + current = current->next; + } while (current != NULL); + return counter; +} + +bool oneElement(List *list) { return list->head->next == NULL; } diff --git a/src/listLesson/list.h b/src/listLesson/list.h new file mode 100644 index 0000000..e658ca4 --- /dev/null +++ b/src/listLesson/list.h @@ -0,0 +1,92 @@ +#pragma once +#include + +// структура обычного элемента в списке +typedef struct ListNode ListNode; + +// структура содержащая указатель на первый элемент списка +typedef struct List List; + +/* + * функция создания нового списка + * ничего не принимает + * возвращает указатель на объект типа List + */ +List* newList(); + +/* + * функция вставки элемента по заданному индексу + * принимает на вход указатель на объект типа List, желаемый индекс и значение + * возвращает булевое значение, сообщающее, удачно ли прошла операция + */ +bool insert(List* list, int index, int value); + +/* + * функция просмотра элемента списка по индексу + * принимает указатель на объект типа List и индекс + * возвращает value элемента + * если что-то пошло не так, вернет -1 + */ +int get(List* list, int index); + +/* + * функция удаления элемента по индексу + * принимает указатель на объект типа List и индекс элемента + * возвращает булевое значние, сообщающее, удачно ли прошла операция + * внутри себя освобождает память удаляемого элемента + */ +bool removeElement(List* list, int index); + +/* + * функция соединения двух списков + * подразумевается, что пользователь передает в ф. два существующих непустых списка + * возвращает указатель типа List на первый элемент первого переданного списка + * !!на данный момент нуждается в доработке!! + */ +List* appendLists(List* list1, List* list2); + +/* + * функция удаления всего списка + * принимает указатель на объект типа List + * внутри себя вызывает функцию removeElement + * возвращает булевое значение, удачно ли прошла операция + */ +bool deleteList(List* list); + +/* + * функция вывода списка в консоль + * принимает только указаетль на список + * ничего не возвращает + * печатает элементы списка через пробел + * в случае переданного пустого или несуществующего списка сообщает об этом пользователю + */ +void printList(List* list); + +/* + * функция которая вставляет элемент в определенное место так, чтобы список всегда оставался отсортированным + * принимает значение и список + * возвращает булевое значение об успешной или неуспешной вставке + */ +bool insert_sorted_in_ascending_order(List* list, int value); + +/* + * функция проверки, пустой ли список + * возвращает true если пустой, false, если нет + * на вход принимает указатель на список + */ +bool isEmpty(List* list); + +/* + * функция, возвращающая длину списка + * принимает на вход указатель на список + * проходится по всем элементам + * возвращает его длину + */ +int getLength(List* list); + +/* + * функция проверки, один ли элемент в списке + * возвращает true если да, false, если нет + * на вход принимает указатель на список + */ +bool oneElement(List* list); diff --git a/src/listLesson/sortedListTask.c b/src/listLesson/sortedListTask.c new file mode 100644 index 0000000..71cd080 --- /dev/null +++ b/src/listLesson/sortedListTask.c @@ -0,0 +1,55 @@ +#include "list.h" +#include +#include + +// подразумевается что пользователь не вводит строки + +int main() { + printf("Вводите команды. После каждой введенной команды нажимайте Enter\n"); + printf("Чтобы завершить работу с программой, введите 0\n"); + int tmp = 0; + List *list = newList(); + int element = 0; + int index = 0; + while (1) { + scanf("%d", &tmp); + if (tmp == 0) { + deleteList(list); + break; + } + if (tmp == 1) { + printf("Введите значение, которое хотите добавить, после того, как " + "введете, нажмите Enter\n"); + scanf("%d", &element); + insert_sorted_in_ascending_order(list, element); + printf("Элемент успешно добавлен\n"); + printf("Введите команду:\n"); + } + if (tmp == 2) { + printf("Введите индекс элемента, который хотите удалить, после того, как " + "введете нажмите Enter\n"); + scanf("%d", &index); + if (removeElement(list, index)) { + printf("Элемент успешно удален.\n"); + printf("Введите команду:\n"); + } else { + printf("Что-то пошло не так. Возможно введен неправильный индекс.\n"); + printf("Введите команду:\n"); + } + } + if (tmp == 3) { + printf("Список элементов:\n"); + printList(list); + printf("Введите команду:\n"); + } else if (tmp != 1 && tmp != 2 && tmp != 3) { + printf("Вероятно, такой команды не существует.\n"); + printf("Введите команду:\n"); + } + } + printf("Работа с программой завершена. Память очищена.\n"); + return 0; +} + +// P.S. Не очень понимаю, почему моя программа так себя ведет, если ввести +// строки, причем не важно в какой момент... +// + я же даже проверку написала на то, что элемент может быть не интовым... From a66db8025486ec54b2072ace3599b96304f51c91 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Sun, 16 Nov 2025 19:35:20 +0300 Subject: [PATCH 2/8] Changed the solving --- src/listLesson/sortedListTask.c | 131 +++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 43 deletions(-) diff --git a/src/listLesson/sortedListTask.c b/src/listLesson/sortedListTask.c index 71cd080..fb7346c 100644 --- a/src/listLesson/sortedListTask.c +++ b/src/listLesson/sortedListTask.c @@ -2,54 +2,99 @@ #include #include -// подразумевается что пользователь не вводит строки - -int main() { - printf("Вводите команды. После каждой введенной команды нажимайте Enter\n"); - printf("Чтобы завершить работу с программой, введите 0\n"); - int tmp = 0; - List *list = newList(); - int element = 0; - int index = 0; - while (1) { - scanf("%d", &tmp); - if (tmp == 0) { - deleteList(list); - break; + +void printMenu() +{ + printf("\n=== МЕНЮ КОМАНД ===\n"); + printf("1 - Добавить элемент (с сортировкой по возрастанию)\n"); + printf("2 - Удалить элемент по индексу\n"); + printf("3 - Вывести список\n"); + printf("0 - Выход из программы\n"); +} + +void clearInputBuffer() +{ + int c; + while ((c = getchar()) != '\n') { } +} + +void addElementInList(List* list) +{ + int element = 0; + printf("Введите элемент который хотите добавить\n"); + + if (scanf("%d", &element) != 1) { + printf("Ошибка: введено некорректное значение!\n"); + clearInputBuffer(); + return; } - if (tmp == 1) { - printf("Введите значение, которое хотите добавить, после того, как " - "введете, нажмите Enter\n"); - scanf("%d", &element); - insert_sorted_in_ascending_order(list, element); - printf("Элемент успешно добавлен\n"); - printf("Введите команду:\n"); + clearInputBuffer(); + insert_sorted_in_ascending_order(list, element); + printf("Элемент успешно добавлен\n"); +} + +void removeElemetFromList(List* list) +{ + int index = 0; + printf("Введите индекс элемента, который хотите удалить: "); + if (scanf("%d", &index) != 1) { + printf("Ошибка: введен некорректный индекс!\n"); + clearInputBuffer(); + return; } - if (tmp == 2) { - printf("Введите индекс элемента, который хотите удалить, после того, как " - "введете нажмите Enter\n"); - scanf("%d", &index); - if (removeElement(list, index)) { + clearInputBuffer(); + + if (removeElement(list, index)) { printf("Элемент успешно удален.\n"); - printf("Введите команду:\n"); - } else { + } else { printf("Что-то пошло не так. Возможно введен неправильный индекс.\n"); - printf("Введите команду:\n"); - } } - if (tmp == 3) { - printf("Список элементов:\n"); - printList(list); - printf("Введите команду:\n"); - } else if (tmp != 1 && tmp != 2 && tmp != 3) { - printf("Вероятно, такой команды не существует.\n"); - printf("Введите команду:\n"); +} + +void printTheList(List* list) +{ + printf("Список элементов:\n"); + printList(list); +} + +void handleCommands() +{ + printf("Вводите команды. После каждой введенной команды нажимайте Enter\n"); + printf("Чтобы завершить работу с программой, введите 0\n\n"); + List* list = newList(); + int command = 0; + while (1) { + printf("Введите команду: "); + if (scanf("%d", &command) != 1) { + printf("Ошибка: пожалуйста, введите число от 0 до 3!\n"); + clearInputBuffer(); + continue; // Пропускаем остаток цикла и начинаем заново + } + clearInputBuffer(); + if (command == 0) { + break; + } + switch (command) { + case 1: + addElementInList(list); + break; + case 2: + removeElemetFromList(list); + break; + case 3: + printTheList(list); + break; + default: + printf("Вероятно, такой команды не существует\n"); + } } - } - printf("Работа с программой завершена. Память очищена.\n"); - return 0; + deleteList(list); + printf("Работа с программой завершена. Память очищена\n"); } -// P.S. Не очень понимаю, почему моя программа так себя ведет, если ввести -// строки, причем не важно в какой момент... -// + я же даже проверку написала на то, что элемент может быть не интовым... +int main() +{ + printMenu(); + handleCommands(); + return 0; +} From 4bb48dc829aebe38c8ee1533de833c6d7cadbd81 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Fri, 28 Nov 2025 16:52:34 +0300 Subject: [PATCH 3/8] Add clang format config --- .clang-format | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..84ea374 --- /dev/null +++ b/.clang-format @@ -0,0 +1,244 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: WebKit +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE \ No newline at end of file From 178a66eb1314433b78c23b8cd86c8293bc192861 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Fri, 28 Nov 2025 16:55:04 +0300 Subject: [PATCH 4/8] use clang-format to all of the files --- src/listLesson/counting.c | 52 ++---- src/listLesson/cyclicList.c | 265 ++++++++++++++++--------------- src/listLesson/cyclicList.h | 18 +-- src/listLesson/list.c | 273 +++++++++++++++++--------------- src/listLesson/sortedListTask.c | 1 - 5 files changed, 297 insertions(+), 312 deletions(-) diff --git a/src/listLesson/counting.c b/src/listLesson/counting.c index 18f329c..dd84435 100644 --- a/src/listLesson/counting.c +++ b/src/listLesson/counting.c @@ -2,47 +2,17 @@ #include "list.h" #include #include -// решение через односвязный список -// знаю, что не по условию, но тоже как вариант реализации -int simpleListRealisation() { - printf("Введите n и m через пробел\n"); - int n = 0; - int m = 0; - scanf("%d %d", &n, &m); - List *list = newList(); - for (int i = 1; i <= n; i++) { - insert(list, i - 1, i); - } - int count = 1; - int index = 0; - while (!oneElement(list)) { - if ((count % m) == 0) { - removeElement(list, index); - // откатываем назад индекс - index--; - } - count++; - index++; - if (index == getLength(list)) { - index = 0; +int main() +{ + printf("Введите n и m через пробел\n"); + int n = 0; + int m = 0; + scanf("%d %d", &n, &m); + List* list = newList(); + for (int i = 1; i <= n; i++) { + insert(list, i - 1, i); } - } - printList(list); - return 0; -} - -// решение через циклический список -int main() { - printf("Введите n и m через пробел\n"); - int n = 0; - int m = 0; - scanf("%d %d", &n, &m); - List *list = newList(); - for (int i = 1; i <= n; i++) { - insert(list, i - 1, i); - } - printf("%d", findTheSafeIndex(list, m)); - - return 0; + printf("%d", findTheSafeIndex(list, m)); + return 0; } diff --git a/src/listLesson/cyclicList.c b/src/listLesson/cyclicList.c index 97c2be0..719e978 100644 --- a/src/listLesson/cyclicList.c +++ b/src/listLesson/cyclicList.c @@ -4,158 +4,165 @@ #include typedef struct ListNode { - int value; - ListNode *next; + int value; + ListNode* next; } ListNode; typedef struct List { - ListNode *head; + ListNode* head; } List; -List *newList() { - List *new = calloc(1, sizeof(*new)); - return new; +List* newList() +{ + List* new = calloc(1, sizeof(*new)); + return new; } -bool insert(List *list, int index, int value) { - if (list == NULL) { - return false; - } - if (isEmpty(list)) { - ListNode *newNode = calloc(1, sizeof(ListNode)); - newNode->value = value; - newNode->next = newNode; - list->head = newNode; - return true; - } - if (index == 0) { - ListNode *newNode = calloc(1, sizeof(ListNode)); - newNode->value = value; - ListNode *current = list->head; - while (current->next != list->head) { - current = current->next; +bool insert(List* list, int index, int value) +{ + if (list == NULL) { + return false; } - newNode->next = list->head; - list->head = newNode; - current->next = newNode; - return true; - } - - ListNode *current = list->head; - int counter = 0; - // условия для while нет, чтобы пользователь мог вставлять элемент на любой - // индекс (так как список цикличный, ему нет разницы какой индекс указали) - while (1) { - if (counter == index - 1) { - ListNode *newNode = calloc(1, sizeof(ListNode)); - newNode->value = value; - newNode->next = current->next; - current->next = newNode; - return true; + if (isEmpty(list)) { + ListNode* newNode = calloc(1, sizeof(ListNode)); + newNode->value = value; + newNode->next = newNode; + list->head = newNode; + return true; + } + if (index == 0) { + ListNode* newNode = calloc(1, sizeof(ListNode)); + newNode->value = value; + ListNode* current = list->head; + while (current->next != list->head) { + current = current->next; + } + newNode->next = list->head; + list->head = newNode; + current->next = newNode; + return true; } - current = current->next; - counter++; - } - return false; -} -bool removeElement(List *list, int index) { - if (list == NULL || isEmpty(list)) { - return false; - } - - if (index == 0) { - ListNode *elemToRemove = list->head; - if (elemToRemove->next == elemToRemove) { - free(elemToRemove); - list->head = NULL; - return true; + ListNode* current = list->head; + int counter = 0; + // условия для while нет, чтобы пользователь мог вставлять элемент на любой + // индекс (так как список цикличный, ему нет разницы какой индекс указали) + while (1) { + if (counter == index - 1) { + ListNode* newNode = calloc(1, sizeof(ListNode)); + newNode->value = value; + newNode->next = current->next; + current->next = newNode; + return true; + } + current = current->next; + counter++; } + return false; +} - ListNode *current = list->head; - while (current->next != elemToRemove) { - current = current->next; +bool removeElement(List* list, int index) +{ + if (list == NULL || isEmpty(list)) { + return false; } - list->head = elemToRemove->next; - current->next = list->head; - free(elemToRemove); - return true; - } - - ListNode *current = list->head; - int counter = 0; - // условия для while нет, чтобы пользователь мог вставлять элемент на любой - // индекс (так как список цикличный, ему нет разницы какой индекс указали) - while (1) { - if (counter == index - 1) { - ListNode *nodeToDelete = current->next; - current->next = nodeToDelete->next; - free(nodeToDelete); - return true; + + if (index == 0) { + ListNode* elemToRemove = list->head; + if (elemToRemove->next == elemToRemove) { + free(elemToRemove); + list->head = NULL; + return true; + } + + ListNode* current = list->head; + while (current->next != elemToRemove) { + current = current->next; + } + list->head = elemToRemove->next; + current->next = list->head; + free(elemToRemove); + return true; } - current = current->next; - counter++; - } - return false; -} -bool deleteList(List *list) { - if (list == NULL || isEmpty(list)) { + ListNode* current = list->head; + int counter = 0; + // условия для while нет, чтобы пользователь мог вставлять элемент на любой + // индекс (так как список цикличный, ему нет разницы какой индекс указали) + while (1) { + if (counter == index - 1) { + ListNode* nodeToDelete = current->next; + current->next = nodeToDelete->next; + free(nodeToDelete); + return true; + } + current = current->next; + counter++; + } return false; - } - while (!isEmpty(list)) { - removeElement(list, 0); - } - free(list); - return true; } -bool isEmpty(List *list) { return list->head == NULL; } - -bool oneElement(List *list) { return list->head->next == list->head; } - -void printList(List *list) { - if (list == NULL || isEmpty(list)) { - printf("Список пустой\n"); - return; - } - ListNode *current = list->head; - do { - printf("%d ", current->value); - current = current->next; - } while (current != list->head); - printf("\n"); +bool deleteList(List* list) +{ + if (list == NULL || isEmpty(list)) { + return false; + } + while (!isEmpty(list)) { + removeElement(list, 0); + } + free(list); + return true; } -int getLength(List *list) { - if (list == NULL || isEmpty(list)) { - return -1; - } - int counter = 0; - ListNode *current = list->head; - do { - counter++; - current = current->next; - } while (current != list->head); - return counter; -} +bool isEmpty(List* list) { return list->head == NULL; } -int findTheSafeIndex(List *list, int m) { - ListNode *current = list->head; - ListNode *prev = NULL; - while (!oneElement(list)) { - for (int i = 0; i < m; i++) { - prev = current; - current = current->next; +bool oneElement(List* list) { return list->head->next == list->head; } + +void printList(List* list) +{ + if (list == NULL || isEmpty(list)) { + printf("Список пустой\n"); + return; } - if (current == list->head) { - list->head = current->next; + ListNode* current = list->head; + do { + printf("%d ", current->value); + current = current->next; + } while (current != list->head); + printf("\n"); +} + +int getLength(List* list) +{ + if (list == NULL || isEmpty(list)) { + return -1; } + int counter = 0; + ListNode* current = list->head; + do { + counter++; + current = current->next; + } while (current != list->head); + return counter; +} - prev->next = current->next; - free(current); - current = prev->next; - } - return list->head->value; +int findTheSafeIndex(List* list, int m) +{ + ListNode* current = list->head; + ListNode* prev = NULL; + while (!oneElement(list)) { + for (int i = 0; i < m; i++) { + prev = current; + current = current->next; + } + if (current == list->head) { + list->head = current->next; + } + + prev->next = current->next; + free(current); + current = prev->next; + } + return list->head->value; } diff --git a/src/listLesson/cyclicList.h b/src/listLesson/cyclicList.h index 4660029..8c0f46d 100644 --- a/src/listLesson/cyclicList.h +++ b/src/listLesson/cyclicList.h @@ -12,14 +12,14 @@ typedef struct List List; * ничего не принимает * возвращает указатель на объект типа List */ -List *newList(); +List* newList(); /* * функция вставки элемента по заданному индексу * принимает на вход указатель на объект типа List, желаемый индекс и значение * возвращает булевое значение, сообщающее, удачно ли прошла операция */ -bool insert(List *list, int index, int value); +bool insert(List* list, int index, int value); /* * функция удаления элемента по индексу @@ -27,7 +27,7 @@ bool insert(List *list, int index, int value); * возвращает булевое значние, сообщающее, удачно ли прошла операция * внутри себя освобождает память удаляемого элемента */ -bool removeElement(List *list, int index); +bool removeElement(List* list, int index); /* * функция удаления всего списка @@ -35,21 +35,21 @@ bool removeElement(List *list, int index); * внутри себя вызывает функцию removeElement * возвращает булевое значение, удачно ли прошла операция */ -bool deleteList(List *list); +bool deleteList(List* list); /* * функция проверки, пустой ли список * возвращает true если пустой, false, если нет * на вход принимает указатель на список */ -bool isEmpty(List *list); +bool isEmpty(List* list); /* * функция проверки, один ли элемент в списке * возвращает true если да, false, если нет * на вход принимает указатель на список */ -bool oneElement(List *list); +bool oneElement(List* list); /* * функция вывода списка в консоль @@ -59,7 +59,7 @@ bool oneElement(List *list); * в случае переданного пустого или несуществующего списка сообщает об этом * пользователю */ -void printList(List *list); +void printList(List* list); /* * функция, возвращающая длину списка @@ -67,7 +67,7 @@ void printList(List *list); * проходится по всем элементам * возвращает его длину */ -int getLength(List *list); +int getLength(List* list); /* * функция алгоритма Иосифа @@ -76,4 +76,4 @@ int getLength(List *list); * куда нужно встать, по условию задачи функция создана исключительно для * реализации алгоритма из файла counting.c. */ -int findTheSafeIndex(List *list, int m); +int findTheSafeIndex(List* list, int m); diff --git a/src/listLesson/list.c b/src/listLesson/list.c index 673ecde..e03d357 100644 --- a/src/listLesson/list.c +++ b/src/listLesson/list.c @@ -4,166 +4,175 @@ #include // структура обычного элемента в списке struct ListNode { - int value; - struct ListNode *next; + int value; + struct ListNode* next; }; // структура содержащая указатель на первый элемент списка struct List { - ListNode *head; + ListNode* head; }; -List *newList() { - List *list = calloc(1, sizeof(*list)); - return list; +List* newList() +{ + List* list = calloc(1, sizeof(*list)); + return list; } -bool insert(List *list, int index, int value) { - if (list == NULL || index < 0) { +bool insert(List* list, int index, int value) +{ + if (list == NULL || index < 0) { + return false; + } + if (index == 0) { + ListNode* newNode = malloc(sizeof(ListNode)); + newNode->value = value; + newNode->next = list->head; + list->head = newNode; + return true; + } + ListNode* current = list->head; + int counter = 0; + while (current != NULL) { + if (counter == index - 1) { + ListNode* newNode = malloc(sizeof(ListNode)); + newNode->value = value; + newNode->next = current->next; + current->next = newNode; + return true; + } + current = current->next; + counter++; + } return false; - } - if (index == 0) { - ListNode *newNode = malloc(sizeof(ListNode)); - newNode->value = value; - newNode->next = list->head; - list->head = newNode; - return true; - } - ListNode *current = list->head; - int counter = 0; - while (current != NULL) { - if (counter == index - 1) { - ListNode *newNode = malloc(sizeof(ListNode)); - newNode->value = value; - newNode->next = current->next; - current->next = newNode; - return true; - } - current = current->next; - counter++; - } - return false; } // а что если пользователь ошибся?? ввел не тот индекс например? что возвращать? -int get(List *list, int index) { - if (list == NULL || isEmpty(list) || index < 0) +int get(List* list, int index) +{ + if (list == NULL || isEmpty(list) || index < 0) + return -1; + if (index == 0) { + return list->head->value; + } + ListNode* current = list->head; + int counter = 0; + while (current != NULL) { + if (counter == index) { + return current->value; + } + current = current->next; + counter++; + } return -1; - if (index == 0) { - return list->head->value; - } - ListNode *current = list->head; - int counter = 0; - while (current != NULL) { - if (counter == index) { - return current->value; - } - current = current->next; - counter++; - } - return -1; } -bool removeElement(List *list, int index) { - if (list == NULL || isEmpty(list) || index < 0) { - return false; - } - ListNode *current = list->head; - if (index == 0) { - list->head = current->next; - free(current); - return true; - } - int counter = 0; - while (current != NULL) { - if (counter == index - 1) { - if (current->next == NULL) +bool removeElement(List* list, int index) +{ + if (list == NULL || isEmpty(list) || index < 0) { return false; - ListNode *nodeToDelete = current->next; - current->next = nodeToDelete->next; - free(nodeToDelete); - return true; - } - current = current->next; - counter++; - } - return false; + } + ListNode* current = list->head; + if (index == 0) { + list->head = current->next; + free(current); + return true; + } + int counter = 0; + while (current != NULL) { + if (counter == index - 1) { + if (current->next == NULL) + return false; + ListNode* nodeToDelete = current->next; + current->next = nodeToDelete->next; + free(nodeToDelete); + return true; + } + current = current->next; + counter++; + } + return false; } -bool deleteList(List *list) { - if (list == NULL || isEmpty(list)) { - return false; - } - while (!isEmpty(list)) { - removeElement(list, 0); - } - free(list); - return true; +bool deleteList(List* list) +{ + if (list == NULL || isEmpty(list)) { + return false; + } + while (!isEmpty(list)) { + removeElement(list, 0); + } + free(list); + return true; } // надо указатель на втоорй список переделать на NULL и сообщить об этом // пользователю там два указаеля надо тип ** -List *appendLists(List *list1, List *list2) { - ListNode *currentIn1 = list1->head; - while (currentIn1->next != NULL) { - currentIn1 = currentIn1->next; - } - currentIn1->next = list2->head; - return list1; +List* appendLists(List* list1, List* list2) +{ + ListNode* currentIn1 = list1->head; + while (currentIn1->next != NULL) { + currentIn1 = currentIn1->next; + } + currentIn1->next = list2->head; + return list1; } -void printList(List *list) { - if (list == NULL || isEmpty(list)) { - printf("Список пустой\n"); - return; - } +void printList(List* list) +{ + if (list == NULL || isEmpty(list)) { + printf("Список пустой\n"); + return; + } - ListNode *current = list->head; - while (current != NULL) { - printf("%d ", current->value); - current = current->next; - } - printf("\n"); + ListNode* current = list->head; + while (current != NULL) { + printf("%d ", current->value); + current = current->next; + } + printf("\n"); } -bool isEmpty(List *list) { return list->head == NULL; } +bool isEmpty(List* list) { return list->head == NULL; } -bool insert_sorted_in_ascending_order(List *list, int value) { - if (list == NULL) { - return false; - } - // случай еще незаполненного списка - if (isEmpty(list)) { - return insert(list, 0, value); - } - ListNode *current = list->head; - int counter = 0; - // если элемент самый маленький и его надо вставить в начало - if (current->value > value) { - return insert(list, 0, value); - } - while (current != NULL && current->next != NULL) { - if ((current->next->value > value) && (current->value <= value)) { - return (insert(list, counter + 1, value)); - } - current = current->next; - counter++; - } - // если программа достигла этой строчки, то значит что элемент больше всех - // остальных - return insert(list, counter + 1, value); +bool insert_sorted_in_ascending_order(List* list, int value) +{ + if (list == NULL) { + return false; + } + // случай еще незаполненного списка + if (isEmpty(list)) { + return insert(list, 0, value); + } + ListNode* current = list->head; + int counter = 0; + // если элемент самый маленький и его надо вставить в начало + if (current->value > value) { + return insert(list, 0, value); + } + while (current != NULL && current->next != NULL) { + if ((current->next->value > value) && (current->value <= value)) { + return (insert(list, counter + 1, value)); + } + current = current->next; + counter++; + } + // если программа достигла этой строчки, то значит что элемент больше всех + // остальных + return insert(list, counter + 1, value); } -int getLength(List *list) { - if (list == NULL || isEmpty(list)) { - return -1; - } - int counter = 0; - ListNode *current = list->head; - do { - counter++; - current = current->next; - } while (current != NULL); - return counter; +int getLength(List* list) +{ + if (list == NULL || isEmpty(list)) { + return -1; + } + int counter = 0; + ListNode* current = list->head; + do { + counter++; + current = current->next; + } while (current != NULL); + return counter; } -bool oneElement(List *list) { return list->head->next == NULL; } +bool oneElement(List* list) { return list->head->next == NULL; } diff --git a/src/listLesson/sortedListTask.c b/src/listLesson/sortedListTask.c index fb7346c..789eef1 100644 --- a/src/listLesson/sortedListTask.c +++ b/src/listLesson/sortedListTask.c @@ -2,7 +2,6 @@ #include #include - void printMenu() { printf("\n=== МЕНЮ КОМАНД ===\n"); From a3c8e20f9f6d9461494cfa491de3dc8671e835d0 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Fri, 28 Nov 2025 16:57:40 +0300 Subject: [PATCH 5/8] Remove useless code from list.c --- src/listLesson/list.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/listLesson/list.c b/src/listLesson/list.c index e03d357..112a575 100644 --- a/src/listLesson/list.c +++ b/src/listLesson/list.c @@ -105,18 +105,6 @@ bool deleteList(List* list) return true; } -// надо указатель на втоорй список переделать на NULL и сообщить об этом -// пользователю там два указаеля надо тип ** -List* appendLists(List* list1, List* list2) -{ - ListNode* currentIn1 = list1->head; - while (currentIn1->next != NULL) { - currentIn1 = currentIn1->next; - } - currentIn1->next = list2->head; - return list1; -} - void printList(List* list) { if (list == NULL || isEmpty(list)) { From 1359820f8962915f5f3f3b1db5f64c08fdd7d82c Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Fri, 28 Nov 2025 17:04:30 +0300 Subject: [PATCH 6/8] Fix some mistakes that i ad in stack tasks --- src/listLesson/cyclicList.c | 3 +++ src/listLesson/cyclicList.h | 3 --- src/listLesson/list.c | 3 +++ src/listLesson/list.h | 3 --- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/listLesson/cyclicList.c b/src/listLesson/cyclicList.c index 719e978..9c31a5f 100644 --- a/src/listLesson/cyclicList.c +++ b/src/listLesson/cyclicList.c @@ -3,6 +3,9 @@ #include #include +// структура обычного элемента в списке +typedef struct ListNode ListNode; + typedef struct ListNode { int value; ListNode* next; diff --git a/src/listLesson/cyclicList.h b/src/listLesson/cyclicList.h index 8c0f46d..c383093 100644 --- a/src/listLesson/cyclicList.h +++ b/src/listLesson/cyclicList.h @@ -1,9 +1,6 @@ #pragma once #include -// структура обычного элемента в списке -typedef struct ListNode ListNode; - // структура содержащая указатель на первый элемент списка typedef struct List List; diff --git a/src/listLesson/list.c b/src/listLesson/list.c index 112a575..eb86229 100644 --- a/src/listLesson/list.c +++ b/src/listLesson/list.c @@ -2,6 +2,9 @@ #include #include #include + +typedef struct ListNode ListNode; + // структура обычного элемента в списке struct ListNode { int value; diff --git a/src/listLesson/list.h b/src/listLesson/list.h index e658ca4..377a36d 100644 --- a/src/listLesson/list.h +++ b/src/listLesson/list.h @@ -1,9 +1,6 @@ #pragma once #include -// структура обычного элемента в списке -typedef struct ListNode ListNode; - // структура содержащая указатель на первый элемент списка typedef struct List List; From 6eb1fc721fb619d5add6bbdacf3c279f3dc03dc2 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Fri, 28 Nov 2025 17:11:16 +0300 Subject: [PATCH 7/8] Add cmake --- CMakeLists.txt | 7 +++++++ src/listLesson/CMakeLists.txt | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/listLesson/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c8b06bf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.25) + +project(C_Homework C) + +add_subdirectory(src/listLesson) + +add_compile_options(-Wall -Wextra -Wpedantic) \ No newline at end of file diff --git a/src/listLesson/CMakeLists.txt b/src/listLesson/CMakeLists.txt new file mode 100644 index 0000000..0b2ed5e --- /dev/null +++ b/src/listLesson/CMakeLists.txt @@ -0,0 +1,11 @@ +add_library(list list.c) + +add_library(cyclicList cyclicList.c) + +add_executable(counting counting.c) + +add_executable(sortedListTask sortedListTask.c) + +target_link_libraries(sortedListTask PRIVATE list) + +target_link_libraries(counting PRIVATE cyclicList) \ No newline at end of file From 986a5df3d567683b88c2467bb31c4e75083eb4e6 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Fri, 28 Nov 2025 17:12:16 +0300 Subject: [PATCH 8/8] Fixxx --- src/listLesson/counting.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/listLesson/counting.c b/src/listLesson/counting.c index dd84435..2753bc4 100644 --- a/src/listLesson/counting.c +++ b/src/listLesson/counting.c @@ -13,6 +13,6 @@ int main() for (int i = 1; i <= n; i++) { insert(list, i - 1, i); } - printf("%d", findTheSafeIndex(list, m)); + printf("%d\n", findTheSafeIndex(list, m)); return 0; }