-
Notifications
You must be signed in to change notification settings - Fork 0
ДЗ № 9.1.1 CMake для домашки № 5, Шестаков Николай #13
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
Open
NicholayShestakov
wants to merge
33
commits into
main
Choose a base branch
from
advanced_bracket_balance_cmake
base: main
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.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
345bc50
Add stack library header file
NicholayShestakov 4737d32
Add stack library realisation file
NicholayShestakov 405bf4c
Update stack header file commentaries
NicholayShestakov ce89c99
Update stack realisation file
NicholayShestakov f4d1e69
Update stack realisation file
NicholayShestakov d389c7d
Update stack header file
NicholayShestakov ceeeb02
Update stack header file
NicholayShestakov f344512
Update stack realisation file
NicholayShestakov caa1bf9
Update stack header file
NicholayShestakov 0d99e19
Update stack realisation file
NicholayShestakov 7f111b6
Add advanced bracket balance homework
NicholayShestakov f70cccd
Update advanced bracket balance homework
NicholayShestakov a64578d
Update bracket balance checker
NicholayShestakov 0af264a
Update bracket balance checker
NicholayShestakov 41b1bd6
Add compile instruction for advanced bracket balance
NicholayShestakov 3dea46b
Update .gitignore with adding ignoring CMake build directory
NicholayShestakov d73f226
Add CMakeLists.txt for build advanced bracket balance
NicholayShestakov ca828c1
Update instructions how to build
NicholayShestakov bce5889
Update stack realization
NicholayShestakov 2526fa5
Update stack header documentation
NicholayShestakov 8e759a7
Update stack header documentation
NicholayShestakov b243309
Update advanced bracket balance checker
NicholayShestakov 1488ca0
Delete build instruction from stack folder
NicholayShestakov 6b648f4
Add build instruction in README
NicholayShestakov 96bb8d6
Add sorting station algorithm
NicholayShestakov b0d02b7
Add compile instruction for sorting station
NicholayShestakov 7f7b0cd
Add CMakeLists.txt for build sorting station
NicholayShestakov e236b6c
Add compile flags for all executables
NicholayShestakov 7bbf2c1
Update sorting station
NicholayShestakov da6c40c
Remove memory leaks
NicholayShestakov 5c1ba87
Update final check for unclosed brackets
NicholayShestakov 45be467
Delete build instruction from stack folder
NicholayShestakov bad6d60
Merge branch 'main' into advanced_bracket_balance_cmake
NicholayShestakov 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| cmake_minimum_required(VERSION 3.25) | ||
| project(sorting_station C) | ||
| project(C_homework C) | ||
| add_compile_options(-Wall -Wextra -pedantic) | ||
|
|
||
| # Libraries | ||
| add_library(stack src/stack_and_queue/stack/stack.c) | ||
|
|
||
| # Executables and links with libraries | ||
| add_executable(advanced_bracket_balance src/stack_and_queue/stack/advanced_bracket_balance.c) | ||
| target_link_libraries(advanced_bracket_balance PRIVATE stack) | ||
|
|
||
| add_executable(sorting_station src/stack_and_queue/stack/sorting_station.c) | ||
| target_link_libraries(sorting_station PRIVATE stack) | ||
| target_compile_options(sorting_station PRIVATE -Wall -Wextra -pedantic) |
This file contains hidden or 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,71 @@ | ||
| #include "stack.h" | ||
| #include <assert.h> | ||
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| bool isOpeningBracket(char c) | ||
| { | ||
| return (c == '(' || c == '[' || c == '{'); | ||
| } | ||
|
|
||
| bool isClosingBracket(char c) | ||
| { | ||
| return (c == ')' || c == ']' || c == '}'); | ||
| } | ||
|
|
||
| // Checks brackets balance. | ||
| // Returns true if brackets balanced and false if not. | ||
| // Takes string. | ||
| bool isBracketsBalanced(char* string) | ||
| { | ||
| int size = strlen(string); | ||
| Stack* brackets = newStack(); | ||
|
|
||
| for (int i = 0; i < size; i++) { | ||
| if (isOpeningBracket(string[i])) { | ||
| push(brackets, string[i]); | ||
| } | ||
| if (isClosingBracket(string[i])) { | ||
| if (isEmpty(brackets)) { | ||
| deleteStack(brackets); | ||
| return false; | ||
| } | ||
|
|
||
| bool isClosed = false; | ||
| switch (pop(brackets)) { | ||
| case '(': | ||
| isClosed = string[i] == ')'; | ||
| break; | ||
| case '[': | ||
| isClosed = string[i] == ']'; | ||
| break; | ||
| case '{': | ||
| isClosed = string[i] == '}'; | ||
| break; | ||
| } | ||
|
|
||
| if (!isClosed) { | ||
| deleteStack(brackets); | ||
| return false; | ||
NicholayShestakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| bool isAllClosed = isEmpty(brackets); | ||
| deleteStack(brackets); | ||
| return isAllClosed; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| assert(isBracketsBalanced("T(e){s}[t]") && "Test failed."); | ||
| assert(isBracketsBalanced("123") && "Test failed."); | ||
| assert(isBracketsBalanced("") && "Test failed."); | ||
| assert(!isBracketsBalanced("(") && "Test failed."); | ||
| assert(!isBracketsBalanced("({a)}") && "Test failed."); | ||
| assert(isBracketsBalanced("((({{{[[[]]]}}})))") && "Test failed."); | ||
| printf("All tests successfully passed.\n"); | ||
|
|
||
| return 0; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.