Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ include(cmake/function.cmake) # подхватываем функции,
# и для создания исполняемого проекта в отдельные функции

add_subdirectory(lib_easy_example) # подключаем дополнительный CMakeLists.txt из подкаталога с именем lib_easy_example
add_subdirectory(stack_lib)
add_subdirectory(checkbreckets)

add_subdirectory(main) # подключаем дополнительный CMakeLists.txt из подкаталога с именем main

option(BTEST "build test?" ON) # указываем подключаем ли google-тесты (ON или YES) или нет (OFF или NO)
Expand Down
2 changes: 2 additions & 0 deletions checkbreckets/CMakeList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create_project_lib(checkbreckets)
add_depend(checkbreckets stack_lib)
2 changes: 2 additions & 0 deletions checkbreckets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create_project_lib(Algorithms)
add_depend(Algorithms stack_lib ..\\stack_lib)
33 changes: 33 additions & 0 deletions checkbreckets/checkbreckets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include <iostream>
#include "checkbreckets.h"


bool check_brackets(const std::string& val) {
int open_count = 0;
for (char c : val) {
if (c == '(' || c == '[' || c == '{') {
open_count++;
}
}
Stack<char> stack(open_count + 1);
for (char c : val) {
if (c == '(' || c == '[' || c == '{') {
stack.push(c);
}
else if (c == ')' || c == ']' || c == '}') {
if (stack.is_empty()) {
return false;
}
char top = stack.top();
if ((c == ')' && top == '(') || (c == ']' && top == '[') || (c == '}' && top == '{')) {
stack.pop();
}
else {
return false;
}
}
}

return stack.is_empty();
}
96 changes: 96 additions & 0 deletions checkbreckets/checkbreckets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#pragma once
#include <stdexcept>
#include <iostream>

template <class T>
class Stack {
T* _data;
int _size, _top;
public:
Stack(int size = 100);
Stack(const Stack& other);
~Stack();
Stack& operator=(const Stack& other);
void push(const T& val);
void pop();
inline T top() const;
inline bool is_empty() const noexcept;
inline bool is_full() const noexcept;
void clear() noexcept;
int capacity() const noexcept { return _size; }
int count() const noexcept { return _top + 1; }
};

template <class T>
Stack<T>::Stack(int size) : _size(size > 0 ? size : 100), _top(-1) {
_data = new T[_size];
}

template <class T>
Stack<T>::Stack(const Stack& other) : _size(other._size), _top(other._top) {
_data = new T[_size];
for (int i = 0; i <= _top; ++i) {
_data[i] = other._data[i];
}
}


template <class T>
Stack<T>::~Stack() {
delete[] _data;
}


template <class T>
Stack<T>& Stack<T>::operator=(const Stack& other) {
if (this != &other) {
delete[] _data;
_size = other._size;
_top = other._top;
_data = new T[_size];
for (int i = 0; i <= _top; ++i) {
_data[i] = other._data[i];
}
}
return *this;
}


template <class T>
void Stack<T>::push(const T& val) {
if (is_full()) {
throw std::logic_error("stack is full");
}
_data[++_top] = val;
}

template <class T>
void Stack<T>::pop() {
if (is_empty()) {
throw std::logic_error("stack is empty");
}
--_top;
}

template <class T>
inline T Stack<T>::top() const {
if (is_empty()) {
throw std::logic_error("stack is empty");
}
return _data[_top];
}

template <class T>
inline bool Stack<T>::is_empty() const noexcept {
return _top == -1;
}

template <class T>
inline bool Stack<T>::is_full() const noexcept {
return _top == _size - 1;
}

template <class T>
void Stack<T>::clear() noexcept {
_top = -1;
}
146 changes: 146 additions & 0 deletions checkbreckets/checkbreckets.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{e8f000ba-1e3c-48a7-88e2-f2640edfc98d}</ProjectGuid>
<RootNamespace>checkbreckets</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>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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" />
<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="checkbreckets.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="checkbreckets.h" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeList.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\build\stack_lib\stack_lib.vcxproj">
<Project>{9fa79273-5cab-343e-a74d-9bde3288771f}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
30 changes: 30 additions & 0 deletions checkbreckets/checkbreckets.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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="checkbreckets.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="checkbreckets.h">
<Filter>Исходные файлы</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeList.txt" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions stack_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_project_lib(stack_lib)
Empty file added stack_lib/stack_lib.cpp
Empty file.
Loading