From cbf3db29b8902ac1dbdd1e8b1dcd13a2916df2e1 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Sun, 16 Nov 2025 16:14:32 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A1=D1=87=D0=B8=D1=82=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 6/loop_sorted_list.c | 65 ++++++++++++++++++++++++++ 6/sorted_list.c | 108 +++++++++++++++++++++++++++++++++++++++++++ 6/sorted_list.h | 22 +++++++++ 3 files changed, 195 insertions(+) create mode 100644 6/loop_sorted_list.c create mode 100644 6/sorted_list.c create mode 100644 6/sorted_list.h diff --git a/6/loop_sorted_list.c b/6/loop_sorted_list.c new file mode 100644 index 0000000..d9e6563 --- /dev/null +++ b/6/loop_sorted_list.c @@ -0,0 +1,65 @@ +#include "sorted_list.h" + +void main() { + List list; + initList(&list); + + int n; + int m; + + printf("Количество войнов: "); + scanf("%d", &n); + + printf("Убивают каждого: "); + scanf("%d", &m); + + if (n <= 0) { + printf("n должно быть > 0\n"); + return; + } + + if (m == 1) { + printf("Нужно встать на %d место\n", n); + return; + } + + for (int i = 1; i <= n; i++) { + addValue(&list, i); + } + + + Node* head = list.head; + + while ((*head).next != NULL) { + head = (*head).next; + } + + (*head).next = list.head; + int num = 1; + + head = list.head; + Node* prev = NULL; + + while (list.size > 1) { + if (num == m) { + (*prev).next = (*head).next; + //free(head); + + head = (*prev).next; + num = 1; + + + list.size--; + + continue; + } + + num++; + prev = head; + head = (*head).next; + } + + printf("Нужно встать на %d место\n", (*head).value); + + +} diff --git a/6/sorted_list.c b/6/sorted_list.c new file mode 100644 index 0000000..39a9210 --- /dev/null +++ b/6/sorted_list.c @@ -0,0 +1,108 @@ +#include "sorted_list.h" + + +void initList(List* list) { + (*list).head = NULL; + (*list).size = 0; +} + +void addValue(List* list, int value) { + Node* head = (*list).head; + + if (head == NULL) { + Node* node = malloc(sizeof(Node)); + (*node).next = NULL; + (*node).value = value; + + (*list).head = node; + (*list).size++; + return; + } + + + + int current = (*head).value; + Node* buff = NULL; + + + while (current < value) { + if ((*head).next == NULL) { + Node* node = malloc(sizeof(Node)); + (*node).next = NULL; + (*node).value = value; + + (*head).next = node; + + (*list).size++; + return; + } + + + buff = head; + head = (*head).next; + + current = (*head).value; + } + + + Node* node = malloc(sizeof(Node)); + (*node).next = head; + (*node).value = value; + + (*list).size++; + + if (buff != NULL) { + (*buff).next = node; + } + + else { + (*list).head = node; + } +} + + +void removeValue(List* list, int value) { + Node* head = (*list).head; + + if (head == NULL) { + return; + } + + if ((*head).next == NULL) { + + } + + Node* buff = NULL; + + while (head != NULL) { + int listValue = (*head).value; + if (listValue == value) { + if (buff != NULL) { + (*buff).next = (*head).next; + } + + else { + (*list).head = (*head).next; + } + + free(head); + (*list).size--; + + return; + } + + buff = head; + head = (*head).next; + } +} + + +void printList(List* list) { + Node* head = (*list).head; + while (head != NULL) { + int value = (*head).value; + printf("%d ", value); + head = (*head).next; + } + printf("\n"); +} diff --git a/6/sorted_list.h b/6/sorted_list.h new file mode 100644 index 0000000..5194370 --- /dev/null +++ b/6/sorted_list.h @@ -0,0 +1,22 @@ +#pragma once +#include +#include + + + +struct Node { + int value; + struct Node* next; + +} typedef Node; + + +struct List { + Node* head; + int size; +} typedef List; + +void initList(List* list); +void addValue(List* list, int value); +void removeValue(List* list, int value); +void printList(List* list); From 14885a42311ec136cce034611fd868a4d6307f9d Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 14 Nov 2025 11:52:41 +0300 Subject: [PATCH 2/5] sorted list task --- 6/main_sorted_list.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 6/main_sorted_list.c diff --git a/6/main_sorted_list.c b/6/main_sorted_list.c new file mode 100644 index 0000000..0ae850e --- /dev/null +++ b/6/main_sorted_list.c @@ -0,0 +1,42 @@ +#include "sorted_list.h" + +void main() { + List list; + initList(&list); + + printf("0 – выйти\n1 – добавить значение в сортированный список\n2 – удалить значение из списка\n3 – распечатать список\n\n"); + + char inp; + printf("Введите команду: "); + scanf("%c", &inp); + + while (inp != '0') { + int value; + switch (inp) { + case '1': + printf("Добавить: "); + scanf("%d", &value); + + addValue(&list, value); + + break; + + case '2': + printf("Удалить: "); + scanf("%d", &value); + + removeValue(&list, value); + + break; + + case '3': + printf("Список: "); + printList(&list); + break; + default: + printf("Введите команду: "); + break; + } + scanf("%c", &inp); + } +} From e00977127d1301218e51584137af24e1d0d641bb Mon Sep 17 00:00:00 2001 From: stuffacc Date: Thu, 25 Dec 2025 12:43:03 +0300 Subject: [PATCH 3/5] sorted lisst update --- 6/main_sorted_list.c | 77 +++++++++--------- 6/sorted_list.c | 184 +++++++++++++++++++++---------------------- 6/sorted_list.h | 16 ++-- 3 files changed, 138 insertions(+), 139 deletions(-) diff --git a/6/main_sorted_list.c b/6/main_sorted_list.c index 0ae850e..ecd2d22 100644 --- a/6/main_sorted_list.c +++ b/6/main_sorted_list.c @@ -1,42 +1,43 @@ #include "sorted_list.h" -void main() { - List list; - initList(&list); - - printf("0 – выйти\n1 – добавить значение в сортированный список\n2 – удалить значение из списка\n3 – распечатать список\n\n"); - - char inp; - printf("Введите команду: "); - scanf("%c", &inp); - - while (inp != '0') { - int value; - switch (inp) { - case '1': - printf("Добавить: "); - scanf("%d", &value); - - addValue(&list, value); - - break; - - case '2': - printf("Удалить: "); - scanf("%d", &value); - - removeValue(&list, value); - - break; - - case '3': - printf("Список: "); - printList(&list); - break; - default: - printf("Введите команду: "); - break; - } - scanf("%c", &inp); +void main(int argc, char* argv[]) +{ + List list; + initList(&list); + + printf("0 – выйти\n1 – добавить значение в сортированный список\n2 – удалить значение из списка\n3 – распечатать список\n\n"); + + char inp; + printf("Введите команду: "); + scanf("%c", &inp); + + while (inp != '0') { + int value; + switch (inp) { + case '1': + printf("Добавить: "); + scanf("%d", &value); + + addValue(&list, value); + + break; + + case '2': + printf("Удалить: "); + scanf("%d", &value); + + removeValue(&list, value); + + break; + + case '3': + printf("Список: "); + printList(&list); + break; + default: + printf("Введите команду: "); + break; } + scanf("%c", &inp); + } } diff --git a/6/sorted_list.c b/6/sorted_list.c index 39a9210..3ca7d5b 100644 --- a/6/sorted_list.c +++ b/6/sorted_list.c @@ -1,108 +1,106 @@ #include "sorted_list.h" - -void initList(List* list) { - (*list).head = NULL; - (*list).size = 0; +void initList(List* list) +{ + (*list).head = NULL; + (*list).size = 0; } -void addValue(List* list, int value) { - Node* head = (*list).head; - - if (head == NULL) { - Node* node = malloc(sizeof(Node)); - (*node).next = NULL; - (*node).value = value; - - (*list).head = node; - (*list).size++; - return; - } - - - - int current = (*head).value; - Node* buff = NULL; - - - while (current < value) { - if ((*head).next == NULL) { - Node* node = malloc(sizeof(Node)); - (*node).next = NULL; - (*node).value = value; - - (*head).next = node; - - (*list).size++; - return; - } - - - buff = head; - head = (*head).next; - - current = (*head).value; - } - - - Node* node = malloc(sizeof(Node)); - (*node).next = head; - (*node).value = value; - - (*list).size++; - - if (buff != NULL) { - (*buff).next = node; - } - - else { - (*list).head = node; - } +Node* createNode(int value, Node* next) +{ + Node* node = malloc(sizeof(Node)); + if (node == NULL) { + printf("Ошибка выделения памяти\n"); + exit(-1); + } + + (*node).next = next; + (*node).value = value; + + return node; } +void addValue(List* list, int value) +{ + Node* head = (*list).head; -void removeValue(List* list, int value) { - Node* head = (*list).head; + if (head == NULL) { + Node* node = createNode(value, NULL); - if (head == NULL) { - return; - } - + (*list).head = node; + (*list).size++; + return; + } + + Node* buff = NULL; + + while (head->value < value) { if ((*head).next == NULL) { - - } - - Node* buff = NULL; - - while (head != NULL) { - int listValue = (*head).value; - if (listValue == value) { - if (buff != NULL) { - (*buff).next = (*head).next; - } - - else { - (*list).head = (*head).next; - } - - free(head); - (*list).size--; - - return; - } - - buff = head; - head = (*head).next; + Node* node = createNode(value, NULL); + + (*head).next = node; + + (*list).size++; + return; } + + buff = head; + head = (*head).next; + } + + Node* node = createNode(value, head); + + (*list).size++; + + if (buff != NULL) { + (*buff).next = node; + } + + else { + (*list).head = node; + } } +void removeValue(List* list, int value) +{ + Node* iter = (*list).head; + + if (iter == NULL) { + return; + } -void printList(List* list) { - Node* head = (*list).head; - while (head != NULL) { - int value = (*head).value; - printf("%d ", value); - head = (*head).next; + Node* buff = NULL; + + while (iter != NULL) { + int listValue = (*iter).value; + if (listValue == value) { + if (buff != NULL) { + (*buff).next = (*iter).next; + } + + else { + (*list).head = (*iter).next; + } + + free(iter); + (*list).size--; + + iter = (*list).head; + continue; } - printf("\n"); + + buff = iter; + iter = (*iter).next; + } +} + +void printList(List* list) +{ + Node* iter = (*list).head; + while (iter != NULL) { + int value = (*iter).value; + printf("%d ", value); + iter = (*iter).next; + } + printf("\n"); } diff --git a/6/sorted_list.h b/6/sorted_list.h index 5194370..e8d60ba 100644 --- a/6/sorted_list.h +++ b/6/sorted_list.h @@ -2,21 +2,21 @@ #include #include - - struct Node { - int value; - struct Node* next; - -} typedef Node; + int value; + struct Node* next; +} typedef Node; struct List { - Node* head; - int size; + Node* head; + int size; } typedef List; void initList(List* list); +Node* createNode(int value, Node* next); + void addValue(List* list, int value); void removeValue(List* list, int value); + void printList(List* list); From 6bdbe024b248c730cbb3627815b833aeff436414 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Thu, 25 Dec 2025 17:08:39 +0300 Subject: [PATCH 4/5] Webkit + FIX --- 6/loop_sorted_list.c | 118 +++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 61 deletions(-) diff --git a/6/loop_sorted_list.c b/6/loop_sorted_list.c index d9e6563..d0f9335 100644 --- a/6/loop_sorted_list.c +++ b/6/loop_sorted_list.c @@ -1,65 +1,61 @@ #include "sorted_list.h" -void main() { - List list; - initList(&list); - - int n; - int m; - - printf("Количество войнов: "); - scanf("%d", &n); - - printf("Убивают каждого: "); - scanf("%d", &m); - - if (n <= 0) { - printf("n должно быть > 0\n"); - return; - } - - if (m == 1) { - printf("Нужно встать на %d место\n", n); - return; - } - - for (int i = 1; i <= n; i++) { - addValue(&list, i); - } - - - Node* head = list.head; - - while ((*head).next != NULL) { - head = (*head).next; - } - - (*head).next = list.head; - int num = 1; - - head = list.head; - Node* prev = NULL; - - while (list.size > 1) { - if (num == m) { - (*prev).next = (*head).next; - //free(head); - - head = (*prev).next; - num = 1; - - - list.size--; - - continue; - } - - num++; - prev = head; - head = (*head).next; +void main() +{ + List list; + initList(&list); + + int n; + int m; + + printf("Количество войнов: "); + scanf("%d", &n); + + printf("Убивают каждого: "); + scanf("%d", &m); + + if (n <= 0) { + printf("n должно быть > 0\n"); + return; + } + + if (m == 1) { + printf("Нужно встать на %d место\n", n); + return; + } + + for (int i = 1; i <= n; i++) { + addValue(&list, i); + } + + Node* head = list.head; + + while (head->next != NULL) { + head = (*head).next; + } + + (*head).next = list.head; + int num = 1; + + head = list.head; + Node* prev = NULL; + + while (list.size > 1) { + if (num == m) { + (*prev).next = (*head).next; + + head = (*prev).next; + num = 1; + + list.size--; + + continue; } - - printf("Нужно встать на %d место\n", (*head).value); - - + + num++; + prev = head; + head = (*head).next; + } + + printf("Нужно встать на %d место\n", (*head).value); } From f2ff3b5d77afe3bb2ac23eb6539c22add96744f4 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Thu, 25 Dec 2025 18:05:29 +0300 Subject: [PATCH 5/5] CMakeLists.txt --- 6/CMakeLists.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 6/CMakeLists.txt diff --git a/6/CMakeLists.txt b/6/CMakeLists.txt new file mode 100644 index 0000000..76ff300 --- /dev/null +++ b/6/CMakeLists.txt @@ -0,0 +1,19 @@ +# Устанавливаем минимальную версию CMake +cmake_minimum_required(VERSION 3.25) +# Указываем название проекта и используемый язык(и) +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) + +project(LoopSortedList C) +project(MainSortedList C) + +# Перечисляем библиотеки +add_library(SortedList sorted_list.c) + +# Указываем исполняемый файл +add_executable(LoopSortedList loop_sorted_list.c) +add_executable(MainSortedList main_sorted_list.c) +# Связываемся с библиотеками +target_link_libraries(LoopSortedList PRIVATE SortedList) + +target_link_libraries(MainSortedList PRIVATE SortedList)