From c73176035de5c2987c1cf21ef525387d07d904b1 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sun, 23 Nov 2025 17:45:15 +0300 Subject: [PATCH 01/12] =?UTF-8?q?CI=20=D0=B4=D0=BB=D1=8F=20clanf-format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .CIclang/.clang-format | 245 ++++++++++++++++++ .CIclang/.github/dependabot.yml | 6 + .CIclang/.github/workflows/build-and-lint.yml | 24 ++ 3 files changed, 275 insertions(+) create mode 100644 .CIclang/.clang-format create mode 100644 .CIclang/.github/dependabot.yml create mode 100644 .CIclang/.github/workflows/build-and-lint.yml diff --git a/.CIclang/.clang-format b/.CIclang/.clang-format new file mode 100644 index 0000000..e2cbc59 --- /dev/null +++ b/.CIclang/.clang-format @@ -0,0 +1,245 @@ +--- +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 diff --git a/.CIclang/.github/dependabot.yml b/.CIclang/.github/dependabot.yml new file mode 100644 index 0000000..355e687 --- /dev/null +++ b/.CIclang/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.CIclang/.github/workflows/build-and-lint.yml b/.CIclang/.github/workflows/build-and-lint.yml new file mode 100644 index 0000000..9d85c5a --- /dev/null +++ b/.CIclang/.github/workflows/build-and-lint.yml @@ -0,0 +1,24 @@ +name: Build and lint + +on: + - push + - pull_request + +jobs: + build-and-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Check format + run: | + find . -path ./build -prune -o -type f -name '*.[c|h]' -print | xargs clang-format-18 --style=file --dry-run -Werror + - name: Configure + run: | + # -DCMAKE_EXPORT_COMPILE_COMMANDS=ON is important for clang-tidy + cmake . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + - name: Build + run: | + cmake --build build + - name: Lint + run: | + run-clang-tidy-18 -p=build \ No newline at end of file From 59d707baf4f63ba5bb8dbc1ca7bb8136418250ca Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sun, 23 Nov 2025 17:54:41 +0300 Subject: [PATCH 02/12] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=84=D0=B0=D0=B9=D0=BB=20build-and-lint.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .CIclang/.github/workflows/build-and-lint.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.CIclang/.github/workflows/build-and-lint.yml b/.CIclang/.github/workflows/build-and-lint.yml index 9d85c5a..a2c12fd 100644 --- a/.CIclang/.github/workflows/build-and-lint.yml +++ b/.CIclang/.github/workflows/build-and-lint.yml @@ -12,13 +12,3 @@ jobs: - name: Check format run: | find . -path ./build -prune -o -type f -name '*.[c|h]' -print | xargs clang-format-18 --style=file --dry-run -Werror - - name: Configure - run: | - # -DCMAKE_EXPORT_COMPILE_COMMANDS=ON is important for clang-tidy - cmake . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - - name: Build - run: | - cmake --build build - - name: Lint - run: | - run-clang-tidy-18 -p=build \ No newline at end of file From 384734ff85a57c880869d4e5ce50e89dc1b6c310 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sat, 20 Dec 2025 22:55:01 +0300 Subject: [PATCH 03/12] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .CIclang/.clang-format => .clang-format | 0 {.CIclang/.github => .github}/dependabot.yml | 0 {.CIclang/.github => .github}/workflows/build-and-lint.yml | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename .CIclang/.clang-format => .clang-format (100%) rename {.CIclang/.github => .github}/dependabot.yml (100%) rename {.CIclang/.github => .github}/workflows/build-and-lint.yml (80%) diff --git a/.CIclang/.clang-format b/.clang-format similarity index 100% rename from .CIclang/.clang-format rename to .clang-format diff --git a/.CIclang/.github/dependabot.yml b/.github/dependabot.yml similarity index 100% rename from .CIclang/.github/dependabot.yml rename to .github/dependabot.yml diff --git a/.CIclang/.github/workflows/build-and-lint.yml b/.github/workflows/build-and-lint.yml similarity index 80% rename from .CIclang/.github/workflows/build-and-lint.yml rename to .github/workflows/build-and-lint.yml index a2c12fd..31983d4 100644 --- a/.CIclang/.github/workflows/build-and-lint.yml +++ b/.github/workflows/build-and-lint.yml @@ -11,4 +11,4 @@ jobs: - uses: actions/checkout@v5 - name: Check format run: | - find . -path ./build -prune -o -type f -name '*.[c|h]' -print | xargs clang-format-18 --style=file --dry-run -Werror + find . -path ./build -prune -o -type f -name '*.[c|h]' -print | xargs clang-format-18 --style=file --dry-run -Werror \ No newline at end of file From 767f66eca0ee8949bb4d7ab465996191dc102174 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sun, 21 Dec 2025 17:55:24 +0300 Subject: [PATCH 04/12] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=BA=D0=B8=20=D0=B2=20=D0=BD=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=20=D0=B8=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.clang-format b/.clang-format index e2cbc59..bda3ac9 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,3 @@ ---- Language: Cpp # BasedOnStyle: WebKit AccessModifierOffset: -4 @@ -241,5 +240,4 @@ WhitespaceSensitiveMacros: - CF_SWIFT_NAME - NS_SWIFT_NAME - PP_STRINGIZE - - STRINGIZE -... \ No newline at end of file + - STRINGIZE \ No newline at end of file From 8bdae0ece4b0e2fbfef8208b1de0e5447991301c Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sun, 21 Dec 2025 20:33:11 +0300 Subject: [PATCH 05/12] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D1=86=D0=B5=D0=BA=D0=BB=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cyclicList/cyclicList.c | 154 ++++++++++++++++++++++++++++++++++++++++ cyclicList/cyclicList.h | 12 ++++ 2 files changed, 166 insertions(+) create mode 100644 cyclicList/cyclicList.c create mode 100644 cyclicList/cyclicList.h diff --git a/cyclicList/cyclicList.c b/cyclicList/cyclicList.c new file mode 100644 index 0000000..8c844a9 --- /dev/null +++ b/cyclicList/cyclicList.c @@ -0,0 +1,154 @@ +#include +#include +#include + +// узел списка +typedef struct ListNode { + // значение + int value; + // ссылка на следующий узел + struct ListNode* next; +} ListNode; + +typedef struct List { + ListNode* head; + ListNode* tail; + // длина + int size; +} List; + +// создание нового списка +List* newList() +{ + List* list = (List*)malloc(sizeof(List)); + list->head = NULL; + list->tail = NULL; + list->size = 0; + return list; +} + +// Проверка на пустоту +bool isEmpty(List* list) +{ + return list->head == NULL || list == NULL; +} + +// получение размера списка +int getSize(List* list) +{ + return list->size; +} + +// вставка элемента +void insert(List* list, int value) +{ + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + + if (isEmpty(list)) { + // первый элемент - указываем на себя самого + newNode->next = newNode; + list->head = newNode; + list->tail = newNode; + } else { + // Новый элемент - указывает на голову + newNode->next = list->head; + // Старый хвост указывает на новый элемент + list->tail->next = newNode; + // Обновляем хвост + list->tail = newNode; + } + + list->size++; +} + +// удаление элемента по значению +bool deleteNode(List* list, int value) +{ + // если список пустой + if (isEmpty(list)) { + return false; + } + + ListNode* current = list->head; + ListNode* prev = list->tail; + + int i = 0; + while (i < list->size) { + if (current->value == value) { + // если удаляем единственный элемент + if (list->size == 1) { + free(current); + list->head = NULL; + list->tail = NULL; + } else { + // удаляем элемент + prev->next = current->next; + + // если удаляем голову + if (current == list->head) { + list->head = current->next; + } + + // если удаляем хвост + if (current == list->tail) { + list->tail = prev; + } + + free(current); + } + + list->size--; + return true; + } + + prev = current; + current = current->next; + i++; + } + + return false; +} + +// вывод списка +void printList(List* list) +{ + if (isEmpty(list)) { + printf("Список пуст\n"); + return; + } + + ListNode* current = list->head; + printf("Список: "); + + int i = 0; + while (i < list->size) { + printf("%d ", current->value); + current = current->next; + i++; + } + + printf("\n"); +} + +// удаление всего списка +void deleteList(List* list) +{ + if (isEmpty(list)) { + free(list); + return; + } + + ListNode* current = list->head; + + int i = 0; + while (i < list->size) { + ListNode* temp = current; + current = current->next; + free(temp); + i++; + } + + list->size = 0; + free(list); +} \ No newline at end of file diff --git a/cyclicList/cyclicList.h b/cyclicList/cyclicList.h new file mode 100644 index 0000000..e5b2901 --- /dev/null +++ b/cyclicList/cyclicList.h @@ -0,0 +1,12 @@ +#pragma once +#include + +typedef struct List List; + +List* newList(); +bool isEmpty(List* list); +int getSize(List* list); +void insert(List* list, int value); +bool deleteNode(List* list, int value); +void printList(List* list); +void deleteList(List* list); From 6e6bfb9bf980449fbba1a1ca20ef321c5779b6f0 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sun, 21 Dec 2025 21:29:22 +0300 Subject: [PATCH 06/12] =?UTF-8?q?=D0=A1=D1=87=D0=B8=D1=82=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=D1=87=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- counting/CMakeLists.txt | 19 ++++++++++++++++++ counting/main.c | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 counting/CMakeLists.txt create mode 100644 counting/main.c diff --git a/counting/CMakeLists.txt b/counting/CMakeLists.txt new file mode 100644 index 0000000..332881d --- /dev/null +++ b/counting/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.25) +project(count C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +# Создаём библиотеку из файла в поддиректории +add_library(cyclicList cyclicList/cyclicList.c) + +# Создаём исполняемый файл из файла в другой поддиректории +add_executable(main counting/main.c) + +# Линкуем библиотеку +target_link_libraries(main PRIVATE cyclicList) + +# Добавляем путь к заголовочным файлам библиотеки +target_include_directories(main PRIVATE + ${CMAKE_SOURCE_DIR}/cyclicList +) \ No newline at end of file diff --git a/counting/main.c b/counting/main.c new file mode 100644 index 0000000..9e37dfb --- /dev/null +++ b/counting/main.c @@ -0,0 +1,44 @@ +#include "../cyclicList/cyclicList.h" +#include +#include +#include + +int main(int argc, char** argv) +{ + // Количество войнов + int n = 0; + // какого война будут убивать + int m = 0; + + while (n <= 0 || m <= 0) { + printf("Введите количество войнов: "); + scanf("%d", &n); + printf("Введите, какого по счету война будут убивать: ") + scanf("d", &m); + } + + List* warriors = newList(); + for (int ind = 1; ind < n + 1; ind++) { + insert(warriors, ind); + } + + int count = 1; + while (getSize(warriors) > 1) { + // Если дошли до m-го воина + if (count == m) { + ListNode* toRemove = current; + current = current->next; + deleteNode(warriors, toRemove->value); + // Сбрасываем счетчик + count = 1; + } else { + // Переходим к следующему воину + current = current->next; + count++; + } + } + printf("Последний выживший был под номером: "); + printList(warriors); + deleteList(warriors); + return 0; +} \ No newline at end of file From 3b95335e8d525f4390d0e3bcdec6ee9aca9a3dba Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Sun, 21 Dec 2025 21:30:21 +0300 Subject: [PATCH 07/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=83=D0=B7=D0=BB=D0=B0,=D1=82.=D0=BA.=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=81=D1=87=D0=B8=D1=82=D0=B0=D0=BB=D0=BE=D1=87=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B1=D0=B5?= =?UTF-8?q?=D0=B3=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D0=BF=D0=BE=20=D1=86?= =?UTF-8?q?=D0=B8=D0=BA=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D1=83=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cyclicList/cyclicList.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cyclicList/cyclicList.h b/cyclicList/cyclicList.h index e5b2901..673edaa 100644 --- a/cyclicList/cyclicList.h +++ b/cyclicList/cyclicList.h @@ -2,6 +2,11 @@ #include typedef struct List List; +// узел списка +typedef struct ListNode { + int value; + struct ListNode* next; +} ListNode; List* newList(); bool isEmpty(List* list); From cc9088a7631d93ff620100ca642136dfc5904429 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Mon, 22 Dec 2025 14:07:46 +0300 Subject: [PATCH 08/12] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=BF=D0=BA=D1=83=20=D0=B4=D0=BB=D1=8F=20=D1=86?= =?UTF-8?q?=D0=B8=D0=BA=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cyclicList/cyclicList.c | 154 ---------------------------------------- cyclicList/cyclicList.h | 17 ----- 2 files changed, 171 deletions(-) delete mode 100644 cyclicList/cyclicList.c delete mode 100644 cyclicList/cyclicList.h diff --git a/cyclicList/cyclicList.c b/cyclicList/cyclicList.c deleted file mode 100644 index 8c844a9..0000000 --- a/cyclicList/cyclicList.c +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include -#include - -// узел списка -typedef struct ListNode { - // значение - int value; - // ссылка на следующий узел - struct ListNode* next; -} ListNode; - -typedef struct List { - ListNode* head; - ListNode* tail; - // длина - int size; -} List; - -// создание нового списка -List* newList() -{ - List* list = (List*)malloc(sizeof(List)); - list->head = NULL; - list->tail = NULL; - list->size = 0; - return list; -} - -// Проверка на пустоту -bool isEmpty(List* list) -{ - return list->head == NULL || list == NULL; -} - -// получение размера списка -int getSize(List* list) -{ - return list->size; -} - -// вставка элемента -void insert(List* list, int value) -{ - ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); - newNode->value = value; - - if (isEmpty(list)) { - // первый элемент - указываем на себя самого - newNode->next = newNode; - list->head = newNode; - list->tail = newNode; - } else { - // Новый элемент - указывает на голову - newNode->next = list->head; - // Старый хвост указывает на новый элемент - list->tail->next = newNode; - // Обновляем хвост - list->tail = newNode; - } - - list->size++; -} - -// удаление элемента по значению -bool deleteNode(List* list, int value) -{ - // если список пустой - if (isEmpty(list)) { - return false; - } - - ListNode* current = list->head; - ListNode* prev = list->tail; - - int i = 0; - while (i < list->size) { - if (current->value == value) { - // если удаляем единственный элемент - if (list->size == 1) { - free(current); - list->head = NULL; - list->tail = NULL; - } else { - // удаляем элемент - prev->next = current->next; - - // если удаляем голову - if (current == list->head) { - list->head = current->next; - } - - // если удаляем хвост - if (current == list->tail) { - list->tail = prev; - } - - free(current); - } - - list->size--; - return true; - } - - prev = current; - current = current->next; - i++; - } - - return false; -} - -// вывод списка -void printList(List* list) -{ - if (isEmpty(list)) { - printf("Список пуст\n"); - return; - } - - ListNode* current = list->head; - printf("Список: "); - - int i = 0; - while (i < list->size) { - printf("%d ", current->value); - current = current->next; - i++; - } - - printf("\n"); -} - -// удаление всего списка -void deleteList(List* list) -{ - if (isEmpty(list)) { - free(list); - return; - } - - ListNode* current = list->head; - - int i = 0; - while (i < list->size) { - ListNode* temp = current; - current = current->next; - free(temp); - i++; - } - - list->size = 0; - free(list); -} \ No newline at end of file diff --git a/cyclicList/cyclicList.h b/cyclicList/cyclicList.h deleted file mode 100644 index 673edaa..0000000 --- a/cyclicList/cyclicList.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include - -typedef struct List List; -// узел списка -typedef struct ListNode { - int value; - struct ListNode* next; -} ListNode; - -List* newList(); -bool isEmpty(List* list); -int getSize(List* list); -void insert(List* list, int value); -bool deleteNode(List* list, int value); -void printList(List* list); -void deleteList(List* list); From 8c2aa413f7a487d379a062925ce17d8674792ea8 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Mon, 22 Dec 2025 14:16:54 +0300 Subject: [PATCH 09/12] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BD=D0=B5=D0=B4=D0=BE=D1=87=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- counting/CMakeLists.txt | 11 +++-------- counting/cyclicList.h | 23 +++++++++++++++++++++++ counting/main.c | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 counting/cyclicList.h diff --git a/counting/CMakeLists.txt b/counting/CMakeLists.txt index 332881d..ef457e6 100644 --- a/counting/CMakeLists.txt +++ b/counting/CMakeLists.txt @@ -5,15 +5,10 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) # Создаём библиотеку из файла в поддиректории -add_library(cyclicList cyclicList/cyclicList.c) +add_library(cyclicList cyclicList.c) # Создаём исполняемый файл из файла в другой поддиректории -add_executable(main counting/main.c) +add_executable(main main.c) # Линкуем библиотеку -target_link_libraries(main PRIVATE cyclicList) - -# Добавляем путь к заголовочным файлам библиотеки -target_include_directories(main PRIVATE - ${CMAKE_SOURCE_DIR}/cyclicList -) \ No newline at end of file +target_link_libraries(main PRIVATE cyclicList) \ No newline at end of file diff --git a/counting/cyclicList.h b/counting/cyclicList.h new file mode 100644 index 0000000..eaea610 --- /dev/null +++ b/counting/cyclicList.h @@ -0,0 +1,23 @@ +#pragma once +#include + +typedef struct List { + ListNode* head; + ListNode* tail; + // длина + int size; +} List; + +// узел списка +typedef struct ListNode { + int value; + struct ListNode* next; +} ListNode; + +List* newList(); +bool isEmpty(List* list); +int getSize(List* list); +void insert(List* list, int value); +bool deleteNode(List* list, int value); +void printList(List* list); +void deleteList(List* list); diff --git a/counting/main.c b/counting/main.c index 9e37dfb..b214f35 100644 --- a/counting/main.c +++ b/counting/main.c @@ -1,4 +1,4 @@ -#include "../cyclicList/cyclicList.h" +#include "cyclicList.h" #include #include #include @@ -22,6 +22,7 @@ int main(int argc, char** argv) insert(warriors, ind); } + ListNode* current = warriors->head; int count = 1; while (getSize(warriors) > 1) { // Если дошли до m-го воина From 52a9763353d5d1847ff7b16d8a138113d4f6fb05 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Mon, 22 Dec 2025 14:19:14 +0300 Subject: [PATCH 10/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20cyclic.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- counting/cyclicList.c | 154 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 counting/cyclicList.c diff --git a/counting/cyclicList.c b/counting/cyclicList.c new file mode 100644 index 0000000..8c844a9 --- /dev/null +++ b/counting/cyclicList.c @@ -0,0 +1,154 @@ +#include +#include +#include + +// узел списка +typedef struct ListNode { + // значение + int value; + // ссылка на следующий узел + struct ListNode* next; +} ListNode; + +typedef struct List { + ListNode* head; + ListNode* tail; + // длина + int size; +} List; + +// создание нового списка +List* newList() +{ + List* list = (List*)malloc(sizeof(List)); + list->head = NULL; + list->tail = NULL; + list->size = 0; + return list; +} + +// Проверка на пустоту +bool isEmpty(List* list) +{ + return list->head == NULL || list == NULL; +} + +// получение размера списка +int getSize(List* list) +{ + return list->size; +} + +// вставка элемента +void insert(List* list, int value) +{ + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + + if (isEmpty(list)) { + // первый элемент - указываем на себя самого + newNode->next = newNode; + list->head = newNode; + list->tail = newNode; + } else { + // Новый элемент - указывает на голову + newNode->next = list->head; + // Старый хвост указывает на новый элемент + list->tail->next = newNode; + // Обновляем хвост + list->tail = newNode; + } + + list->size++; +} + +// удаление элемента по значению +bool deleteNode(List* list, int value) +{ + // если список пустой + if (isEmpty(list)) { + return false; + } + + ListNode* current = list->head; + ListNode* prev = list->tail; + + int i = 0; + while (i < list->size) { + if (current->value == value) { + // если удаляем единственный элемент + if (list->size == 1) { + free(current); + list->head = NULL; + list->tail = NULL; + } else { + // удаляем элемент + prev->next = current->next; + + // если удаляем голову + if (current == list->head) { + list->head = current->next; + } + + // если удаляем хвост + if (current == list->tail) { + list->tail = prev; + } + + free(current); + } + + list->size--; + return true; + } + + prev = current; + current = current->next; + i++; + } + + return false; +} + +// вывод списка +void printList(List* list) +{ + if (isEmpty(list)) { + printf("Список пуст\n"); + return; + } + + ListNode* current = list->head; + printf("Список: "); + + int i = 0; + while (i < list->size) { + printf("%d ", current->value); + current = current->next; + i++; + } + + printf("\n"); +} + +// удаление всего списка +void deleteList(List* list) +{ + if (isEmpty(list)) { + free(list); + return; + } + + ListNode* current = list->head; + + int i = 0; + while (i < list->size) { + ListNode* temp = current; + current = current->next; + free(temp); + i++; + } + + list->size = 0; + free(list); +} \ No newline at end of file From 9546c269333ea7422574aa87e84ad3797c30ca57 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Mon, 22 Dec 2025 15:02:02 +0300 Subject: [PATCH 11/12] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B5=D1=89=D0=B5=20=D0=BE=D0=B4=D0=BD=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=B4=D0=BE=D1=87=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- counting/cyclicList.h | 12 ++++++------ counting/main.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/counting/cyclicList.h b/counting/cyclicList.h index eaea610..816b106 100644 --- a/counting/cyclicList.h +++ b/counting/cyclicList.h @@ -1,6 +1,12 @@ #pragma once #include +// узел списка +typedef struct ListNode { + int value; + struct ListNode* next; +} ListNode; + typedef struct List { ListNode* head; ListNode* tail; @@ -8,12 +14,6 @@ typedef struct List { int size; } List; -// узел списка -typedef struct ListNode { - int value; - struct ListNode* next; -} ListNode; - List* newList(); bool isEmpty(List* list); int getSize(List* list); diff --git a/counting/main.c b/counting/main.c index b214f35..6115635 100644 --- a/counting/main.c +++ b/counting/main.c @@ -13,8 +13,8 @@ int main(int argc, char** argv) while (n <= 0 || m <= 0) { printf("Введите количество войнов: "); scanf("%d", &n); - printf("Введите, какого по счету война будут убивать: ") - scanf("d", &m); + printf("Введите, какого по счету война будут убивать: "); + scanf("d", &m); } List* warriors = newList(); From d6037dde609d5035e3c9a4a1695cbe93fe72f951 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Mon, 22 Dec 2025 15:50:33 +0300 Subject: [PATCH 12/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20%=20=D0=B2=20%d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- counting/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/counting/main.c b/counting/main.c index 6115635..6e19594 100644 --- a/counting/main.c +++ b/counting/main.c @@ -5,7 +5,7 @@ int main(int argc, char** argv) { - // Количество войнов + // Количество воинов int n = 0; // какого война будут убивать int m = 0; @@ -14,7 +14,7 @@ int main(int argc, char** argv) printf("Введите количество войнов: "); scanf("%d", &n); printf("Введите, какого по счету война будут убивать: "); - scanf("d", &m); + scanf("%d", &m); } List* warriors = newList();