-
Notifications
You must be signed in to change notification settings - Fork 0
Sorted station. Kalsina Yana #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ef7191b
b6b1a3f
f1357e9
563bbe8
aa47c61
431a7b1
223c5da
605ac32
c9615ee
ca673b6
2ede7da
6a2b7e5
fc02fab
b214c45
7f3b850
e55babf
ea16d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| cmake_minimum_required(VERSION 3.25) | ||
|
|
||
| project(C_Homework) | ||
|
|
||
| add_subdirectory(src/SortingStation) | ||
|
|
||
| add_compile_options(-Wall -Wextra -Wpedantic) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| add_executable(sortingStation sortingStation.c) | ||
|
|
||
| add_library(stack stack.c) | ||
|
|
||
| target_link_libraries(sortingStation PRIVATE stack) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #include "stack.h" | ||
| #include <ctype.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| // функция для определения приоритета операнда +- это 1, * / это 2 | ||
| int getPriority(char operand) | ||
| { | ||
| if (operand == '+' || operand == '-') { | ||
| return 1; | ||
| } else if (operand == '*' || operand == '/') { | ||
| return 2; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| char* convertString(char* string) | ||
| { | ||
| struct Stack* stack = newStack(); | ||
| char* queue = malloc(1000 * sizeof(char)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут память утекает |
||
| int len = strlen(string); | ||
| int queueEndPtr = 0; | ||
| int i = 0; | ||
| while (i != len) { | ||
| // если число | ||
| if (isdigit(string[i])) { | ||
| queue[queueEndPtr] = string[i]; | ||
| ++queueEndPtr; | ||
| queue[queueEndPtr] = ' '; | ||
| ++queueEndPtr; | ||
| } | ||
| // если открывающаяся скобка, добавляем ее в стек | ||
| if (string[i] == '(') { | ||
| push(stack, string[i]); | ||
| } | ||
| // если закрывающаяся, то переберем все значения стека и разместим их в очереди, пока не встретится открывающая скобка | ||
| else if (string[i] == ')') { | ||
| while ((!isEmpty(stack)) && (peek(stack) != '(')) { | ||
| queue[queueEndPtr] = pop(stack); | ||
| ++queueEndPtr; | ||
| queue[queueEndPtr] = ' '; | ||
| ++queueEndPtr; | ||
| } | ||
| if ((!isEmpty(stack)) && (peek(stack) == '(')) { | ||
| pop(stack); | ||
| } else if (!isEmpty(stack)) { | ||
| deleteStack(stack); | ||
| return "ERROR: you missed openning bracket symbol"; | ||
| } | ||
| } | ||
| // если операторы + - * / | ||
| if ((string[i] == '+') || (string[i] == '-') || (string[i] == '*') || (string[i] == '/')) { | ||
| // если оператор, но по приоритету такой же или меньший чем в стеке | ||
| while ((!isEmpty(stack)) && (getPriority(string[i]) <= getPriority(peek(stack)))) { | ||
| queue[queueEndPtr] = pop(stack); | ||
| ++queueEndPtr; | ||
| queue[queueEndPtr] = ' '; | ||
| ++queueEndPtr; | ||
| } | ||
| push(stack, string[i]); | ||
| } | ||
| ++i; | ||
| } | ||
| while (!isEmpty(stack)) { | ||
| if (peek(stack) == '(') { | ||
| deleteStack(stack); | ||
| return "ERROR: you missed closing bracket symbol"; | ||
| } | ||
| queue[queueEndPtr] = pop(stack); | ||
| ++queueEndPtr; | ||
| queue[queueEndPtr] = ' '; | ||
| ++queueEndPtr; | ||
| } | ||
|
|
||
| deleteStack(stack); | ||
| // чтобы строка была корректной | ||
| queue[queueEndPtr] = '\0'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хорошо бы ещё |
||
| char* queue_realloced = realloc(queue, sizeof(char) * (strlen(queue) + 1)); | ||
| free(stack); | ||
| return queue_realloced; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Давайте я сделаю вид, что я не видел, что Вы накосячили с неймингом.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. господи, простите.... Чего-то я с питона не переключилась... |
||
| } | ||
|
|
||
| /* | ||
| Предполагается, что пользователь вводит корректное арифметическое выражение. | ||
| Но в программе предусмотрено, если пользователь забудет одну из скобок. | ||
| */ | ||
|
|
||
| int main() | ||
| { | ||
| char* arifmeticExpression = malloc(1001 * sizeof(char)); | ||
| // 1001 так как последний символ отводится для \0 | ||
| printf("Введите выражение, не превышающее по длине 1001 символов\n"); | ||
| fgets(arifmeticExpression, 1001, stdin); | ||
| char* queue = convertString(arifmeticExpression); | ||
| int queueLength = strlen(queue); | ||
| printf("%s\n", queue); | ||
| free(queue); | ||
| free(arifmeticExpression); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут всё ещё что-то странно с английским языком, но пусть это будет Вашей проблемой, а не моей.