Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ef7191b
Add stack.c and stack.h
yaprogrammer18-yanchi Oct 11, 2025
b6b1a3f
Slightly change stack.c and stack.h
yaprogrammer18-yanchi Oct 13, 2025
8eec1d6
Add advancedBracketBalance task
yaprogrammer18-yanchi Oct 13, 2025
24094b3
Remove empty line
yaprogrammer18-yanchi Oct 14, 2025
00d5be0
Removed struct realisation from h to c and fix some mistakes that thi…
yaprogrammer18-yanchi Oct 24, 2025
aa47c61
update stack version in more advanced one
yaprogrammer18-yanchi Oct 25, 2025
4dcee2c
Resolve the conflict in stack.c and stack.h files
yaprogrammer18-yanchi Oct 25, 2025
df951c6
Add cmake files, changed the file strusture. Now AdvBrBal task and st…
yaprogrammer18-yanchi Nov 2, 2025
4f596e8
Changed one letter in CMakelists.txt
yaprogrammer18-yanchi Nov 2, 2025
29c0959
Changed one more letter in CMakelists.txt
yaprogrammer18-yanchi Nov 2, 2025
6917e2c
Changed and one more letter in CMakelists.txt
yaprogrammer18-yanchi Nov 2, 2025
c68f8ae
Revert "Changed one more letter in CMakelists.txt"
yaprogrammer18-yanchi Nov 2, 2025
076cddd
Changed one letter in CMake file
yaprogrammer18-yanchi Nov 2, 2025
b9f38cf
Add flags in cMake file
yaprogrammer18-yanchi Nov 2, 2025
ca673b6
Add clang-format config
yaprogrammer18-yanchi Nov 25, 2025
2ede7da
Fix mistakes in stack.h and stack.c
yaprogrammer18-yanchi Nov 25, 2025
6a2b7e5
Fix other mistakes in stack.c add built in .gitignore
yaprogrammer18-yanchi Nov 25, 2025
03128ee
Add clang-format config + resolved the conflict with stack files
yaprogrammer18-yanchi Nov 25, 2025
d0aa365
Fix advanced braket balance task
yaprogrammer18-yanchi Nov 25, 2025
b936d74
Changed stack.h and main file just removed some empty spaces
yaprogrammer18-yanchi Nov 25, 2025
ab8c2c1
fix stack.h
yaprogrammer18-yanchi Nov 25, 2025
83d1991
tmp to ch comspile to compile added break on 31 line
yaprogrammer18-yanchi Dec 16, 2025
d67a2dc
ch now is new with every iteration
yaprogrammer18-yanchi Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 244 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

build
# End of https://www.toptal.com/developers/gitignore/api/c
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.25)

project(C_Homework C)

add_subdirectory(src/AdvancedBracketBalance)

add_compile_options(-Wall -Wextra -Wpedantic)
5 changes: 5 additions & 0 deletions src/AdvancedBracketBalance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_library(stack stack.c)

add_executable(advancedBracketBalance advancedBracketBalance.c)

target_link_libraries(advancedBracketBalance PRIVATE stack)
53 changes: 53 additions & 0 deletions src/AdvancedBracketBalance/advancedBracketBalance.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "stack.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

bool checkBrackets(char* stringWithBrackets)
{
bool isBalanced = true;
Stack* stack = newStack();
int length = strlen(stringWithBrackets);
for (int i = 0; i < length; i++) {
char ch = stringWithBrackets[i];
if ((ch == '(') || (ch == '{') || (ch == '[')) {
push(stack, ch);
}
// если встретилась закрывающаяся и стек не пустой
else if ((ch == ')' || ch == '}' || ch == ']') && (!isEmpty(stack))) {
char previousBracket = pop(stack);
if ((previousBracket == '(' && ch == ')') || (previousBracket == '[' && ch == ']') || (previousBracket == '{' && ch == '}')) {
continue;
} else {
isBalanced = false;
break;
}
}
// закрывающаяся и пустой стек
else if ((ch == ')' || ch == '}' || ch == ']') && (isEmpty(stack))) {
isBalanced = false;
break;
}
}
if (!isEmpty(stack)) {
isBalanced = false;
}
deleteStack(stack);
return isBalanced;
}

int main()
{
char* stringWithBrackets = malloc(1000 * sizeof(char));
printf("Введите скобочную последовательность: ");
scanf("%s", stringWithBrackets);
bool isCorrect = checkBrackets(stringWithBrackets);
if (isCorrect) {
printf("Скобочная последовательность правильная\n");
} else {
printf("Скобочная последовательность неправильная\n");
}
free(stringWithBrackets);
return 0;
}
56 changes: 56 additions & 0 deletions src/AdvancedBracketBalance/stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "stack.h"
#include <stdbool.h>
#include <stdlib.h>

// структура обыкновенного элемента в стеке
typedef struct StackNode StackNode;

struct StackNode {
int value;
struct StackNode* next;
};

// сам стек (структура содержащая указатель на первый элемент стека)
struct Stack {
struct StackNode* head;
};

Stack* newStack(void)
{
Stack* stack = calloc(1, sizeof(*stack));
return stack;
}

void push(Stack* stack, int value)
{
StackNode* node = malloc(sizeof(StackNode));
node->value = value;
node->next = stack->head;
stack->head = node;
}

int pop(Stack* stack)
{
StackNode* oldNode = stack->head;
int res = oldNode->value;
stack->head = oldNode->next;
free(oldNode);
return res;
}

int peek(struct Stack* stack)
{
StackNode* headNode = stack->head;
int res = headNode->value;
return res;
}

bool isEmpty(Stack* stack) { return stack->head == NULL; }

void deleteStack(Stack* stack)
{
while (!isEmpty(stack)) {
pop(stack);
}
free(stack);
}
Loading