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/sortList.c b/number1/sortList.c new file mode 100644 index 0000000..59e98b2 --- /dev/null +++ b/number1/sortList.c @@ -0,0 +1,102 @@ +#include "sortList.h" +#include +#include + +// элемент списка +typedef struct ListNode { + // значение + int value; + // ссылка на следующую "ячейку" + struct ListNode* next; +} ListNode; + +typedef struct List { + ListNode* head; +} List; + +List* newList(){ + List* list = { NULL }; + return list; +} + +// положить элемент в соответствии с сортировкой +void insert(List* list, int value) +{ + ListNode* newNode = (ListNode*)malloc(sizeof(ListNode)); + newNode->value = value; + newNode->next = NULL; + + // Если список пуст или новый элемент меньше головы + if (list->head == NULL || value < list->head->value) { + newNode->next = list->head; + list->head = newNode; + return; + } + + // поиск того, куда вставить новый элемент + ListNode* current = list->head; + while (current->next != NULL && current->next->value < value) { + current = current->next; + } + + // вставка + newNode->next = current->next; + current->next = newNode; +} + +// проверка на возможность удаления элемента +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 ", current->value); + 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/binComparison.c b/number2/binComparison.c new file mode 100644 index 0000000..85987af --- /dev/null +++ b/number2/binComparison.c @@ -0,0 +1,34 @@ +#include +#include + +int min(int a, int b) +{ + if (a > b) { + return b; + } else { + return a; + } +} + +// проверяет, что первое больше второго +bool compar(bool num1[], bool num2[], int size1, int size2) +{ + int minInd = min(size1, size2); + int i1 = 0; + int i2 = 0; + while (i1 < minInd && i2 < minInd) { + if (num1[i1] < num2[i2]) { + return false; + break; + } + i1++; + i2++; + } + if (size1 > size2) { + return true; + } else if (size1 < size2) { + return false; + } + + return true; +} \ No newline at end of file diff --git a/number2/test.c b/number2/test.c new file mode 100644 index 0000000..a67b901 --- /dev/null +++ b/number2/test.c @@ -0,0 +1,49 @@ +#include "binComparison" +#include +#include +#include +#include + +bool run_tests() +{ + int s = 0; + + bool a[] = { 1, 0, 1 }; + bool b[] = { 1, 1, 1 }; + int size1 = sizeof(a) / sizeof(a[0]) int size1 = sizeof(b) / sizeof(b[0]) + + if (!compar(a, b, size1, size2)) + { + s++; + } + + bool c[] = { 1, 1, 1, 1 }; + bool d[] = { 1, 1, 1 }; + int size3 = sizeof(c) / sizeof(c[0]); + int size4 = sizeof(d) / sizeof(d[0]); + + if (compar(c, d, size3, size4)) { + s++; + } + + bool e[] = { 1, 1, 0 }; + bool f[] = { 0, 1, 1 }; + int size5 = sizeof(e) / sizeof(e[0]); + int size6 = sizeof(f) / sizeof(f[0]); + if (compar(e, f, size5, size6)) { + s++; + } + + return s == 3; +} + +int main(int argc, char* argv[]) +{ + if (argc == 2 && strcmp(argv[1], "--test") == 0) { + if (run_tests()) { + return 0; + } else { + return 1; + } + } +} \ No newline at end of file