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..a2c12fd --- /dev/null +++ b/.CIclang/.github/workflows/build-and-lint.yml @@ -0,0 +1,14 @@ +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 diff --git a/number1/CMakeLists.txt b/number1/CMakeLists.txt new file mode 100644 index 0000000..8f3dd2f --- /dev/null +++ b/number1/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.25) + +project(rewrite C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +add_library(sortList sortList.c) + +add_executable(main main.c) + +target_link_libraries(main PRIVATE sortList) diff --git a/number1/main.c b/number1/main.c new file mode 100644 index 0000000..32775be --- /dev/null +++ b/number1/main.c @@ -0,0 +1,28 @@ +#include "sortList.h" +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + List* list = newList(); + int value = 0; + + int nul = 0; + deleteNode(list, nul); + + char numbers[1000]; + printf("Введите набор чисел:\n"); + fgets(numbers, sizeof(numbers), stdin); + char* token = strtok(numbers, " "); + while (token != NULL) { + int number = atoi(token); + insert(list, number); + token = strtok(NULL, " "); + } + printList(list); + deleteList(list); + + return 0; +} \ No newline at end of file diff --git a/number1/sortList.c b/number1/sortList.c new file mode 100644 index 0000000..2f52f37 --- /dev/null +++ b/number1/sortList.c @@ -0,0 +1,124 @@ +#include "sortList.h" +#include +#include + +// элемент списка +typedef struct ListNode { + // значение + int value; + // сколько раз ввели значение + int count; + // ссылка на следующую "ячейку" + struct ListNode* next; +} ListNode; + +typedef struct List { + ListNode* head; +} List; + +List* newList() +{ + List* list = (List*)malloc(sizeof(List)); + list->head = NULL; + return list; +} + +// положить элемент в соответствии с сортировкой +void insert(List* list, int value) +{ + + // Если список пуст или новый элемент меньше головы + if (list->head == NULL || value < list->head->value) { + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + newNode->count = 1; + newNode->next = NULL; + + newNode->next = list->head; + list->head = newNode; + return; + } + + // поиск того, куда вставить новый элемент + ListNode* current = list->head; + while (current->next != NULL && current->next->value < value) { + current = current->next; + // printf("%d", current->next->value); + } + + if (current->next != NULL && current->next->value == value) { + current->next->count++; + return; + } else if (current->value == value) { + current->count++; + + } else { + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + newNode->count = 1; + newNode->next = NULL; + + // вставка + newNode->next = current->next; + current->next = newNode; + + return; + } +} + +// проверка на возможность удаления элемента +bool deleteNode(List* list, int value) +{ + // если список пустой + if (list->head == NULL) { + return false; + } + + // если элемент это голова + if (list->head->value == value) { + ListNode* temprery = list->head; + list->head = list->head->next; + free(temprery); + return true; + } + + // поиск элемента для удаления + ListNode* current = list->head; + while (current->next != NULL && current->next->value != value) { + current = current->next; + } + + // Если элемент не найден + if (current->next == NULL) { + return false; + } + + // удаление элемента + ListNode* temprery = current->next; + current->next = current->next->next; + free(temprery); + return true; +} + +// вывод списка +void printList(List* list) +{ + ListNode* current = list->head; + while (current != NULL) { + printf("%d:%d, ", current->value, current->count); + current = current->next; + } + printf("\n"); +} + +// удаление списка +void deleteList(List* list) +{ + ListNode* current = list->head; + while (current != NULL) { + ListNode* temprery = current; + current = current->next; + free(temprery); + } + list->head = NULL; +} \ No newline at end of file diff --git a/number1/sortList.h b/number1/sortList.h new file mode 100644 index 0000000..50bee5d --- /dev/null +++ b/number1/sortList.h @@ -0,0 +1,11 @@ +#pragma once +#include + +typedef struct List List; + + +List* newList(); +void insert(List* list, int value); +bool deleteNode(List* list, int value); +void printList(List* list); +void deleteList(List* list); \ No newline at end of file diff --git a/number2/CMakeLists.txt b/number2/CMakeLists.txt new file mode 100644 index 0000000..fb30665 --- /dev/null +++ b/number2/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.25) + +project(testSortList C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +add_library(sortList sortList.c) + +add_executable(main main.c) + +target_link_libraries(main PRIVATE sortList) + +add_executable(tests testsList.c) + +target_link_libraries(tests PRIVATE sortList) + +enable_testing() + +add_test( + NAME test + COMMAND tests +) diff --git a/number2/sortList.c b/number2/sortList.c new file mode 100644 index 0000000..4747e67 --- /dev/null +++ b/number2/sortList.c @@ -0,0 +1,159 @@ +#include "sortList.h" +#include +#include +#include + +// элемент списка +typedef struct ListNode { + // значение + int value; + // сколько раз ввели значение + int count; + // ссылка на следующую "ячейку" + struct ListNode* next; +} ListNode; + +typedef struct List { + ListNode* head; +} List; + +List* newList() +{ + List* list = (List*)malloc(sizeof(List)); + list->head = NULL; + return list; +} + +// положить элемент в соответствии с сортировкой +void insert(List* list, int value) +{ + + // Если список пуст или новый элемент меньше головы + if (list->head == NULL || value < list->head->value) { + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + newNode->count = 1; + newNode->next = NULL; + + newNode->next = list->head; + list->head = newNode; + return; + } + + // поиск того, куда вставить новый элемент + ListNode* current = list->head; + while (current->next != NULL && current->next->value < value) { + current = current->next; + // printf("%d", current->next->value); + } + + if (current->next != NULL && current->next->value == value) { + current->next->count++; + return; + } else if (current->value == value) { + current->count++; + + } else { + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + newNode->count = 1; + newNode->next = NULL; + + // вставка + newNode->next = current->next; + current->next = newNode; + + return; + } +} + +// проверка на возможность удаления элемента +bool deleteNode(List* list, int value) +{ + // если список пустой + if (list->head == NULL) { + return false; + } + + // если элемент это голова + if (list->head->value == value) { + ListNode* temprery = list->head; + list->head = list->head->next; + free(temprery); + return true; + } + + // поиск элемента для удаления + ListNode* current = list->head; + while (current->next != NULL && current->next->value != value) { + current = current->next; + } + + // Если элемент не найден + if (current->next == NULL) { + return false; + } + + // удаление элемента + ListNode* temprery = current->next; + current->next = current->next->next; + free(temprery); + return true; +} + +// вывод списка +void printList(List* list) +{ + ListNode* current = list->head; + while (current != NULL) { + printf("%d:%d, ", current->value, current->count); + current = current->next; + } + printf("\n"); +} + +// удаление списка +void deleteList(List* list) +{ + ListNode* current = list->head; + while (current != NULL) { + ListNode* temprery = current; + current = current->next; + free(temprery); + } + list->head = NULL; +} + +int minPermutation(int number) +{ + List* list = newList(); + + int degree = 0; + while (number > 0) { + insert(list, number % 10); + number = number / 10; + degree++; + } + + int tempDegree = 0; + if (list->head->value == 0) { + tempDegree = list->head->count; + } + + int miniNumber = 0; + ListNode* current = list->head; + if (list->head->value == 0) { + current = current->next; + miniNumber += current->value * pow(10, degree); + degree--; + degree = degree - tempDegree; + } + while (current != NULL) { + for (int i = 0; i < current->count; i++) { + miniNumber += current->value * pow(10, degree); + degree--; + } + current = current->next; + } + return miniNumber; +} \ No newline at end of file diff --git a/number2/sortList.h b/number2/sortList.h new file mode 100644 index 0000000..60e8263 --- /dev/null +++ b/number2/sortList.h @@ -0,0 +1,12 @@ +#pragma once +#include + +typedef struct List List; + + +List* newList(); +int minNumber(int number); +void insert(List* list, int value); +bool deleteNode(List* list, int value); +void printList(List* list); +void deleteList(List* list); \ No newline at end of file