-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bracket sequence #9
Open
viktoriia-fomina
wants to merge
12
commits into
master
Choose a base branch
from
bracket-sequence
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+474
−0
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
94609dc
some changes
viktoriia-fomina efc2041
made structure stack
viktoriia-fomina 4d07785
trying to make function that checks if bracket sequence is correct
viktoriia-fomina 2bb51d9
function that checks seems ready
viktoriia-fomina 60fbd81
changed design in functions for brackets
viktoriia-fomina 54c7a52
Deleted useless destructor in Element. Added const to methods in Stack
viktoriia-fomina 9533022
fixed some remarks. Made definitions in some functions smaller. Delet…
viktoriia-fomina 41f713d
Deted using namespace std in h files. Fixed small remark in ~Stack()
viktoriia-fomina 4146470
Fixed small bug: added std in Stack.cpp
viktoriia-fomina 927b90a
fixed remark
viktoriia-fomina 9e72313
deleted commented code
viktoriia-fomina 52d86bf
added tests
viktoriia-fomina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 15 | ||
VisualStudioVersion = 15.0.27703.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bracket sequence", "bracket sequence\bracket sequence.vcxproj", "{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}" | ||
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 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Debug|x64.ActiveCfg = Debug|x64 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Debug|x64.Build.0 = Debug|x64 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Debug|x86.Build.0 = Debug|Win32 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Release|x64.ActiveCfg = Release|x64 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Release|x64.Build.0 = Release|x64 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Release|x86.ActiveCfg = Release|Win32 | ||
{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A3CDAC60-BE3A-42CD-AD96-73C4C1E3F3A4} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "Element.h" | ||
|
||
Element::Element(char data = '\0') | ||
{ | ||
this->data = data; | ||
this->next = nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
struct Element | ||
{ | ||
explicit Element(char data); | ||
|
||
char data; | ||
Element* next; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "Stack.h" | ||
#include "Element.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
Stack::Stack() | ||
{ | ||
head = nullptr; | ||
} | ||
|
||
Stack::~Stack() | ||
{ | ||
while (!isEmpty()) | ||
{ | ||
auto* temp = head; | ||
head = temp->next; | ||
temp->next = nullptr; | ||
delete temp; | ||
} | ||
} | ||
|
||
void Stack::push(char data) | ||
{ | ||
auto* newElement = new Element(data); | ||
if (!isEmpty()) | ||
{ | ||
newElement->next = head; | ||
} | ||
head = newElement; | ||
} | ||
|
||
bool Stack::pop() | ||
{ | ||
if (isEmpty()) | ||
{ | ||
return false; | ||
} | ||
auto* temp = head->next; | ||
head->next = nullptr; | ||
delete head; | ||
head = temp; | ||
return true; | ||
} | ||
|
||
char Stack::peek() const | ||
{ | ||
if (!isEmpty()) | ||
{ | ||
return head->data; | ||
} | ||
cout << "Stack is empty\n"; | ||
return '\0'; | ||
} | ||
|
||
bool Stack::isEmpty() const | ||
{ | ||
return head == nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
struct Element; | ||
|
||
struct Stack | ||
{ | ||
// ����������� | ||
Stack(); | ||
|
||
// ���������� | ||
~Stack(); | ||
|
||
// ���������� �������� � ������ | ||
void push(char data); | ||
|
||
// �������� �������� �� ������ | ||
bool pop(); | ||
|
||
// ���������� �� �������� ������� | ||
char peek() const; | ||
|
||
// ��������� �������� �� ���� ������ | ||
bool isEmpty() const; | ||
private: | ||
Element* head; | ||
}; |
75 changes: 75 additions & 0 deletions
75
hw6/bracket sequence/bracket sequence/bracket sequence.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "bracket sequence.h" | ||
#include "Stack.h" | ||
|
||
bool isBracket(char const symbol); | ||
bool ifClosingBracket(char const symbol); | ||
bool ifOpeningBracket(char const symbol); | ||
bool ifPairOfBrackets(char const openingBracket, char const closingBracket); | ||
|
||
bool ifBracketSequenceIsCorrect(std::string const & str) | ||
{ | ||
Stack s; | ||
for (int i = 0; i < str.size(); ++i) | ||
{ | ||
if (isBracket(str[i])) | ||
{ | ||
if (s.isEmpty()) | ||
{ | ||
if (!ifOpeningBracket(str[i])) | ||
{ | ||
return false; | ||
} | ||
s.push(str[i]); | ||
} | ||
else | ||
{ | ||
if (ifClosingBracket(str[i])) | ||
{ | ||
if (!ifPairOfBrackets(s.peek(), str[i])) | ||
{ | ||
return false; | ||
} | ||
s.pop(); | ||
} | ||
else | ||
{ | ||
s.push(str[i]); | ||
} | ||
} | ||
} | ||
} | ||
return s.isEmpty(); | ||
} | ||
|
||
bool isBracket(char const symbol) | ||
{ | ||
return (symbol == '(' || symbol == ')' || symbol == '[' || symbol == ']' || | ||
symbol == '{' || symbol == '}'); | ||
} | ||
|
||
bool ifClosingBracket(char const symbol) | ||
{ | ||
return (symbol == ')' || symbol == ']' || symbol == '}'); | ||
} | ||
|
||
bool ifOpeningBracket(char const symbol) | ||
{ | ||
return (symbol == '(' || symbol == '[' || symbol == '{'); | ||
} | ||
|
||
bool ifPairOfBrackets(char const openingBracket, char const closingBracket) | ||
{ | ||
if (openingBracket == '(' && closingBracket == ')') | ||
{ | ||
return true; | ||
} | ||
if (openingBracket == '[' && closingBracket == ']') | ||
{ | ||
return true; | ||
} | ||
if (openingBracket == '{' && closingBracket == '}') | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
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. И даже это :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
bool ifBracketSequenceIsCorrect(std::string const & str); |
136 changes: 136 additions & 0 deletions
136
hw6/bracket sequence/bracket sequence/bracket sequence.vcxproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="15.0" 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>15.0</VCProjectVersion> | ||
<ProjectGuid>{E0E7D27A-9576-458F-B076-FBF3A2DEB9C8}</ProjectGuid> | ||
<RootNamespace>bracketsequence</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0.17134.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>v141</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</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 /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="Element.cpp" /> | ||
<ClCompile Include="bracket sequence.cpp" /> | ||
<ClCompile Include="main.cpp" /> | ||
<ClCompile Include="Stack.cpp" /> | ||
<ClCompile Include="tests.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="Element.h" /> | ||
<ClInclude Include="bracket sequence.h" /> | ||
<ClInclude Include="Stack.h" /> | ||
<ClInclude Include="tests.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
В принципе, если стек пуст, то head у него nullptr, так что
newElement->next = head;
ничего плохого не сделает и проверка не нужна. Но как у Вас --- более читабельно и логично, поэтому тоже ок.