-
Notifications
You must be signed in to change notification settings - Fork 1
commit #1
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
spirinamayya
wants to merge
10
commits into
dev
Choose a base branch
from
master
base: dev
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
commit #1
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a4ceb5
commit
spirinamayya f732c61
update
spirinamayya df90803
Ds_store
spirinamayya a133817
idea
spirinamayya 1726d0e
idea
spirinamayya 94167fc
step back
spirinamayya 2198964
final
spirinamayya 48f0ba6
Create README.md
spirinamayya f3e3f12
Add files via upload
spirinamayya 0f95f34
Update README.md
spirinamayya 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
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,8 @@ | ||
| #include "Application.h" | ||
|
|
||
| namespace mvc { | ||
| Application::Application() { | ||
| view_.subscribe(controller_.input()); | ||
| model_.subscribe(view_.input()); | ||
| } | ||
| }// namespace mvc |
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,18 @@ | ||
| #ifndef COURSEPROJECT_APPLICATION_H | ||
| #define COURSEPROJECT_APPLICATION_H | ||
|
|
||
| #include "Controller.h" | ||
|
|
||
| namespace mvc { | ||
| class Application { | ||
| public: | ||
| Application(); | ||
|
|
||
| private: | ||
| AVLTree model_; | ||
| View view_; | ||
| Controller controller_{&model_}; | ||
| }; | ||
| }// namespace mvc | ||
|
|
||
| #endif//COURSEPROJECT_APPLICATION_H |
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,24 @@ | ||
| cmake_minimum_required(VERSION 3.24) | ||
| project(CourseProject) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CXX_STANDARD_REQUIRED ON) | ||
| set(CMAKE_AUTOMOC ON) | ||
| set(CMAKE_AUTORCC ON) | ||
| set(CMAKE_AUTOUIC ON) | ||
|
|
||
| set(CMAKE_PREFIX_PATH "/opt/homebrew/opt/qt/lib/cmake") | ||
|
|
||
| find_package(Qt6 COMPONENTS | ||
| Core | ||
| Gui | ||
| Widgets | ||
| REQUIRED) | ||
|
|
||
| add_executable(CourseProject main.cpp mainwindow.cpp mainwindow.ui Model.cpp View.cpp Controller.cpp InfoTree.cpp aboutwindow.cpp Application.cpp) | ||
| target_link_libraries(CourseProject | ||
| Qt::Core | ||
| Qt::Gui | ||
| Qt::Widgets | ||
| ) | ||
|
|
||
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,29 @@ | ||
| #include "Controller.h" | ||
|
|
||
| namespace mvc { | ||
| Controller::Controller(AVLTree *model) | ||
| : model_(model) { | ||
| } | ||
|
|
||
| void Controller::action(const ViewData &data) { | ||
| switch (data.operation) { | ||
| case View::Operation::Add: { | ||
| model_->insert(data.value); | ||
| break; | ||
| } | ||
| case View::Operation::Delete: { | ||
| model_->deleteNode(data.value); | ||
| break; | ||
| } | ||
| case View::Operation::Search: { | ||
| model_->search(data.value); | ||
| break; | ||
| } | ||
| case View::Operation::DeleteAll: { | ||
| model_->deleteAll(); | ||
| } | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| }// namespace mvc |
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,28 @@ | ||
| #ifndef COURSEPROJECT_CONTROLLER_H | ||
| #define COURSEPROJECT_CONTROLLER_H | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "Model.h" | ||
| #include "View.h" | ||
|
|
||
| namespace mvc { | ||
| class Controller { | ||
| private: | ||
| using ViewData = View::Command; | ||
| using Observer = NSLibrary::CObserver<ViewData>; | ||
| using Input = NSLibrary::CColdInput<ViewData>; | ||
|
|
||
| public: | ||
| Controller(AVLTree *ptr); | ||
| Observer *input() { return &observer_; } | ||
|
|
||
| private: | ||
| void action(const ViewData &data); | ||
|
|
||
| AVLTree *model_; | ||
| Input observer_ = [this](const ViewData &data) { action(data); }; | ||
| }; | ||
| }// namespace mvc | ||
|
|
||
| #endif//COURSEPROJECT_CONTROLLER_H |
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,131 @@ | ||
| #include "InfoTree.h" | ||
|
|
||
| namespace mvc { | ||
| InfoTree::~InfoTree() { | ||
| clear(root_); | ||
| } | ||
|
|
||
| std::pair<int, bool> InfoTree::findValue(int x, int y) { | ||
| if (this == nullptr) | ||
| return {0, false}; | ||
| std::queue<Info *> que; | ||
| que.push(root_); | ||
| Info *cur; | ||
| while (!que.empty()) { | ||
| cur = que.front(); | ||
| que.pop(); | ||
| if ((x > cur->x - kRadius_ && x < cur->x + kRadius_) && (y > cur->y - kRadius_ && y < cur->y + kRadius_)) | ||
| return {cur->key, true}; | ||
| if (cur->left != nullptr) | ||
| que.push(cur->left); | ||
| if (cur->right != nullptr) | ||
| que.push(cur->right); | ||
| } | ||
| return {0, false}; | ||
| } | ||
|
|
||
| void InfoTree::clear(Info *treeInfo) { | ||
| if (treeInfo != nullptr) { | ||
| clear(treeInfo->left); | ||
| clear(treeInfo->right); | ||
| delete treeInfo; | ||
| } | ||
| } | ||
|
|
||
| void InfoTree::setWidth(Info *cur) { | ||
| if (cur == nullptr) | ||
| return; | ||
| setWidth(cur->left); | ||
| setWidth(cur->right); | ||
|
|
||
| if (cur->right == nullptr && cur->left == nullptr) | ||
| cur->width = 2 * kRadius_; | ||
| else if (cur->left == nullptr) | ||
| cur->width = 2 * cur->right->width + kWidth_; | ||
| else if (cur->right == nullptr) | ||
| cur->width = 2 * cur->left->width + kWidth_; | ||
| else | ||
| cur->width = 2 * std::max(cur->left->width, cur->right->width) + kWidth_; | ||
| } | ||
|
|
||
| void InfoTree::setXCoord(Info *cur, std::queue<Info *> &que, int &count, int ×Next, int ×Now) { | ||
| if (cur->left != nullptr) { | ||
| que.push(cur->left); | ||
| ++timesNext; | ||
| cur->left->x = cur->x - kWidth_ / 2 - cur->left->width / 2; | ||
| } | ||
| if (cur->right != nullptr) { | ||
| que.push(cur->right); | ||
| ++timesNext; | ||
| cur->right->x = cur->x + kWidth_ / 2 + cur->right->width / 2; | ||
| } | ||
| --timesNow; | ||
| if (timesNow == 0) { | ||
| ++count; | ||
| timesNow = timesNext; | ||
| timesNext = 0; | ||
| } | ||
| } | ||
|
|
||
| void InfoTree::calcXCoord() { | ||
| Info *coord = root_; | ||
| setWidth(coord); | ||
| Info *root = root_; | ||
| if (root == nullptr) | ||
| return; | ||
| std::queue<Info *> que; | ||
| que.push(root); | ||
| Info *cur; | ||
| int count = 0, timesNow = 1, timesNext = 0; | ||
| while (!que.empty()) { | ||
DimaTrushin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cur = que.front(); | ||
| que.pop(); | ||
| setXCoord(cur, que, count, timesNext, timesNow); | ||
| } | ||
| } | ||
|
|
||
| Info *InfoTree::buildInfoTree(const Node *node) { | ||
| if (node == nullptr) | ||
| return nullptr; | ||
| else { | ||
| Info *temp = new Info; | ||
| temp->key = node->key; | ||
| temp->left = buildInfoTree(node->leftCh); | ||
| temp->right = buildInfoTree(node->rightCh); | ||
| return temp; | ||
| } | ||
| } | ||
|
|
||
| void InfoTree::setYCoord(Info *cur, std::queue<Info *> &que, int &count, int ×Next, int ×Now) { | ||
| cur->y = count * (2 * kRadius_ + kHeight_); | ||
| if (cur->left != nullptr) { | ||
| que.push(cur->left); | ||
| ++timesNext; | ||
| } | ||
| if (cur->right != nullptr) { | ||
| que.push(cur->right); | ||
| ++timesNext; | ||
| } | ||
| --timesNow; | ||
| if (timesNow == 0) { | ||
| ++count; | ||
| timesNow = timesNext; | ||
| timesNext = 0; | ||
| } | ||
| } | ||
|
|
||
| void InfoTree::calcYCoord() { | ||
| Info *root = root_; | ||
| if (root == nullptr) | ||
| return; | ||
| std::queue<Info *> que; | ||
| que.push(root); | ||
|
Comment on lines
+121
to
+122
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. Это ты от рекурсии избавлялась? |
||
| Info *cur; | ||
| int count = 0, timesNow = 1, timesNext = 0; | ||
| while (!que.empty()) { | ||
| cur = que.front(); | ||
| que.pop(); | ||
| setYCoord(cur, que, count, timesNext, timesNow); | ||
| } | ||
| } | ||
| }// namespace mvc | ||
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,49 @@ | ||
| #ifndef COURSEPROJECT_INFOTREE_H | ||
| #define COURSEPROJECT_INFOTREE_H | ||
|
|
||
| #include <queue> | ||
|
|
||
| #include "Model.h" | ||
|
|
||
| namespace mvc { | ||
|
|
||
| struct Info { | ||
| int x = 0; | ||
| int y = 0; | ||
| int key; | ||
| Info *left; | ||
| Info *right; | ||
| int width; | ||
| }; | ||
|
|
||
| class InfoTree { | ||
| public: | ||
| InfoTree(const Node *rootGet) | ||
| : root_(buildInfoTree(rootGet)) { | ||
| calcYCoord(); | ||
| calcXCoord(); | ||
| } | ||
| ~InfoTree(); | ||
| Info *getRoot() { return root_; } | ||
| std::pair<int, bool> findValue(int x, int y); | ||
| void clear(Info *treeInfo); | ||
|
|
||
| private: | ||
| static constexpr int kRadius_ = 40; | ||
| static constexpr int kHeight_ = 30; | ||
| static constexpr int kWidth_ = 15; | ||
|
|
||
| private: | ||
| void setWidth(Info *cur); | ||
| void setXCoord(Info *cur, std::queue<Info *> &que, int &count, int ×Next, int ×Now); | ||
| void calcXCoord(); | ||
| Info *buildInfoTree(const Node *node); | ||
| void setYCoord(Info *cur, std::queue<Info *> &que, int &count, int ×Next, int ×Now); | ||
| void calcYCoord(); | ||
|
|
||
| Info *root_ = nullptr; | ||
| }; | ||
|
|
||
| }// namespace mvc | ||
|
|
||
| #endif//COURSEPROJECT_INFOTREE_H |
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.
Uh oh!
There was an error while loading. Please reload this page.