Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1a83386
creating functions for working with the stack and testing them
MinyazevR Oct 15, 2021
2549f2f
fixed bugs
MinyazevR Oct 15, 2021
14417f4
Merge branch 'main' of https://github.com/MinyazevR/Homework-1-sem in…
MinyazevR Oct 15, 2021
8d6727e
fixed bugs
MinyazevR Oct 15, 2021
e7e22d6
add function
MinyazevR Oct 16, 2021
2f9e2a0
fixed bugs
MinyazevR Oct 16, 2021
a04a9a8
writing all functions, text and comments
MinyazevR Oct 16, 2021
ac6b390
fixed bugs
MinyazevR Oct 16, 2021
015e87e
fixed bugs
MinyazevR Oct 16, 2021
5d2e300
Merge pull request #16 from MinyazevR/Stack
MinyazevR Oct 16, 2021
d85663e
fixed bugs
MinyazevR Oct 22, 2021
6a502c1
fixed bugs
MinyazevR Oct 22, 2021
cf515a4
Merge pull request #21 from MinyazevR/Stack
MinyazevR Oct 22, 2021
77c9d15
fixed bugs
MinyazevR Oct 22, 2021
0dfb7c2
fixed bugs
MinyazevR Oct 22, 2021
b720cdc
adding a function that returns the value of an element from the top o…
MinyazevR Oct 22, 2021
22af234
Merge pull request #22 from MinyazevR/Stack
MinyazevR Oct 22, 2021
c713a82
fixed bugs
MinyazevR Oct 22, 2021
9a45a27
fixed bugs
MinyazevR Oct 22, 2021
ae4b6a9
fixed bugs
MinyazevR Oct 22, 2021
e226c08
fixed test
MinyazevR Oct 23, 2021
13aa804
correction of an error related to the absence of main.c
MinyazevR Oct 23, 2021
954da9f
correction of defects related to the styleguide
MinyazevR Oct 23, 2021
a121942
fixed bugs
MinyazevR Oct 23, 2021
fe152de
adding a test for a function
MinyazevR Oct 23, 2021
1e1980f
Merge branch 'BalanceBrackets' into Stack
MinyazevR Oct 23, 2021
bb748f8
Merge pull request #26 from MinyazevR/Stack
MinyazevR Oct 23, 2021
022b692
fixed bugs
MinyazevR Oct 23, 2021
7f6d2c3
removed unnecessary .h
MinyazevR Oct 23, 2021
7fe9a12
the error with the error code has been changed, the tests have been c…
MinyazevR Oct 25, 2021
ad099c8
fixed bugs related to the error value
MinyazevR Oct 25, 2021
f6c2352
changing the code according to the style guide
MinyazevR Oct 25, 2021
6c04a72
adding const
MinyazevR Oct 25, 2021
5f1e13d
adding const
MinyazevR Oct 25, 2021
4fee312
changing tests, function arguments
MinyazevR Oct 25, 2021
cb50cd2
Added a check for push()
MinyazevR Oct 25, 2021
8e7b5a1
changing functions, tests
MinyazevR Oct 25, 2021
f50a25c
fixed errors in the main function
MinyazevR Oct 25, 2021
bcf969b
delete space
MinyazevR Oct 26, 2021
12dbf94
fixed pop()
MinyazevR Oct 26, 2021
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
31 changes: 31 additions & 0 deletions BalanceBrackets/BalanceBrackets.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BalanceBrackets", "BalanceBrackets\BalanceBrackets.vcxproj", "{2095AD51-1509-4999-A54D-827860784952}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2095AD51-1509-4999-A54D-827860784952}.Debug|x64.ActiveCfg = Debug|x64
{2095AD51-1509-4999-A54D-827860784952}.Debug|x64.Build.0 = Debug|x64
{2095AD51-1509-4999-A54D-827860784952}.Debug|x86.ActiveCfg = Debug|Win32
{2095AD51-1509-4999-A54D-827860784952}.Debug|x86.Build.0 = Debug|Win32
{2095AD51-1509-4999-A54D-827860784952}.Release|x64.ActiveCfg = Release|x64
{2095AD51-1509-4999-A54D-827860784952}.Release|x64.Build.0 = Release|x64
{2095AD51-1509-4999-A54D-827860784952}.Release|x86.ActiveCfg = Release|Win32
{2095AD51-1509-4999-A54D-827860784952}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {241DB504-44F6-401D-9485-FE90894D17CA}
EndGlobalSection
EndGlobal
65 changes: 65 additions & 0 deletions BalanceBrackets/BalanceBrackets/BalanceBrackets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "BalanceBrackets.h"
#include "../../Stack/Stack/Stack.h"

bool isOpeningBracket(char parentheses)
{
return parentheses == '(' || parentheses == '{' || parentheses == '[';
}

bool isClosingBracket(char paretheses)
{
return paretheses == ')' || paretheses == '}' || paretheses == ']';
}

bool openingAndClosingOfTheSameType(char openingParetheses, char closingParetheses)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, что лучше бы подошло "notOpeningAndClosingOfTheSameType", или в самой функции поправить и в месте вызова "!" писать

{
return openingParetheses != '(' && closingParetheses == ')'
|| openingParetheses != '{' && closingParetheses == '}'
|| openingParetheses != '[' && closingParetheses == ']';
}

bool checkCorrectOrderBrackets(const char* expressionFromParentheses, int* errorCode)
{
Stack* head = createStack();
int counter = 0;
while (expressionFromParentheses[counter] != '\0')
{
if (isOpeningBracket(expressionFromParentheses[counter]))
{
int error = 0;
push(&head, expressionFromParentheses[counter], &error);
if (error == 2)
{
*errorCode = 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кстати, можно было тогда уж в push сразу errorCode передавать :) Но тогда стоило бы его сделать нулём в начале функции и гарантировать, что как только он не 0, мы тут же выходим.

deleteStack(&head);
return false;
}
}
else if (isClosingBracket(expressionFromParentheses[counter]))
{
int error = 0;
char topOfTheStack = (char)pop(&head, &error);
if (error == 1)
{
*errorCode = 1;
deleteStack(&head);
return false;

This comment was marked as resolved.

}
if (openingAndClosingOfTheSameType(topOfTheStack, expressionFromParentheses[counter]))
{
*errorCode = 1;
deleteStack(&head);
return false;
}
}
counter++;
}
if (isEmpty(head))
{
deleteStack(&head);
return true;

This comment was marked as resolved.

}
*errorCode = 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы тут 0 оставил. Функция корректно отработала, просто скобочная последовательность не корректна (на то Вы true/false и возвращаете)

deleteStack(&head);
return false;
}
5 changes: 5 additions & 0 deletions BalanceBrackets/BalanceBrackets/BalanceBrackets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <stdbool.h>

// Function to check the correct position of the brackets
bool checkCorrectOrderBrackets(const char* expressionFromParentheses, int* errorCode);
155 changes: 155 additions & 0 deletions BalanceBrackets/BalanceBrackets/BalanceBrackets.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{2095ad51-1509-4999-a54d-827860784952}</ProjectGuid>
<RootNamespace>BalanceBrackets</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\Stack\Stack\Stack.c" />
<ClCompile Include="BalanceBrackets.c" />
<ClCompile Include="BalanceBracketsTest.c" />
<ClCompile Include="Main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Stack\Stack\Stack.h" />
<ClInclude Include="BalanceBrackets.h" />
<ClInclude Include="BalanceBracketsTest.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
42 changes: 42 additions & 0 deletions BalanceBrackets/BalanceBrackets/BalanceBrackets.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BalanceBrackets.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="BalanceBracketsTest.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="..\..\Stack\Stack\Stack.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="Main.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BalanceBrackets.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="..\..\Stack\Stack\Stack.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="BalanceBracketsTest.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions BalanceBrackets/BalanceBrackets/BalanceBracketsTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "BalanceBracketsTest.h"
#include "BalanceBrackets.h"

bool balanceBracketsTest()
{
int errors[14] = {0};
return checkCorrectOrderBrackets("((15 - x) - (13 + 45) * ( 1 0 - 1 6))", &errors[0])
&& checkCorrectOrderBrackets("(([(){()}][]{}{}{()}))", &errors[1])
&& checkCorrectOrderBrackets("([[]({})]({}(())))", &errors[2])
&& checkCorrectOrderBrackets("(x * x) * ( c - a)", &errors[3])
&& checkCorrectOrderBrackets("[[]]{{}}(())", &errors[4])
&& checkCorrectOrderBrackets("(({{{}[]}[]}[]))", &errors[5])
&& checkCorrectOrderBrackets("{}()[]", &errors[6])
&& !checkCorrectOrderBrackets("{{", &errors[7])
&& !checkCorrectOrderBrackets("{())[][]}", &errors[8])
&& !checkCorrectOrderBrackets("(x-a)*(c+a))", &errors[9])
&& !checkCorrectOrderBrackets("(]])()()[][]{}{{}}", &errors[10])
&& !checkCorrectOrderBrackets("{()[]{}{{))))))(}", &errors[11])
&& !checkCorrectOrderBrackets("{{}}(((", &errors[12])
&& !checkCorrectOrderBrackets("(", &errors[13])
&& errors[0] == 0
&& errors[1] == 0
&& errors[2] == 0
&& errors[3] == 0
&& errors[4] == 0
&& errors[5] == 0
&& errors[6] == 0
&& errors[7] == 1
&& errors[8] == 1
&& errors[9] == 1
&& errors[10] == 1
&& errors[11] == 1
&& errors[12] == 1
&& errors[13] == 1;
}
5 changes: 5 additions & 0 deletions BalanceBrackets/BalanceBrackets/BalanceBracketsTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <stdbool.h>

// Function for testing a function that checks for the correct position of the brackets
bool balanceBracketsTest();
28 changes: 28 additions & 0 deletions BalanceBrackets/BalanceBrackets/Main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "BalanceBrackets.h"
#include "BalanceBracketsTest.h"
#include <stdio.h>

int main()
{
if (!balanceBracketsTest())
{
printf("Test failed");
return -1;
}
char expressionFromParentheses[250] = { '\0' };
printf("enter the expression that you want to check for the correct placement of brackets\n");
scanf_s("%[^\n]s", expressionFromParentheses, (unsigned)sizeof(expressionFromParentheses));
int errorCode = 0;
checkCorrectOrderBrackets(expressionFromParentheses, &errorCode);
if (errorCode == 1)
{
printf("The balance of the brackets is incorrect");
return 0;
}
if (errorCode == 2)
{
printf("Insufficient memory");
return -1;
}
printf("The balance of the brackets is correct");
}
Loading