-
Notifications
You must be signed in to change notification settings - Fork 23
Graph class ~/lib/src #5
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
LightAboveFighter
wants to merge
33
commits into
AlgorithmsDafeMipt2024:main
Choose a base branch
from
LightAboveFighter:main
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 13 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4540813
Graph class ~/lib/src
LightAboveFighter f9b6ed9
simple Graph
LightAboveFighter f28131b
task_01
LightAboveFighter 177a3a4
task_04
LightAboveFighter 0630f42
format
LightAboveFighter 72c8f79
Merge branch 'main' into main
LightAboveFighter 6a5fd0e
test base task_01
LightAboveFighter 1466e47
Merge branch 'main' of https://github.com/LightAboveFighter/autumn_ho…
LightAboveFighter 5cf054a
format
LightAboveFighter de3cf01
fix includes
LightAboveFighter 87cbbc5
clang tidy advices
LightAboveFighter 03ee99e
tests task_01
LightAboveFighter c3a46c5
fix tests
LightAboveFighter 7de22a7
task_02
LightAboveFighter c7b68c0
format
LightAboveFighter 9a84bec
split task_01 to .hpp .cpp files
LightAboveFighter e3bf6a2
task_04
LightAboveFighter e49a06a
convenient graph node constructor
LightAboveFighter 4364e13
clang tidy
LightAboveFighter b022189
format
LightAboveFighter c42ad03
format
LightAboveFighter b367fa7
fix include deleted files
LightAboveFighter f89348b
task_05
LightAboveFighter dd2a6e6
clang tidy + delete dublicates
LightAboveFighter be0cfeb
graph const method
LightAboveFighter 0a3102e
task_05 turn into classes
LightAboveFighter 4d9a06b
format
LightAboveFighter 724bdcf
task_06
LightAboveFighter be184a5
task_03
LightAboveFighter a16ce56
fix swap
LightAboveFighter 0d5b061
remove extra lines
LightAboveFighter e802244
task_06_tests
LightAboveFighter e5381d7
formatter's advices
LightAboveFighter 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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #ifndef GRAPH_H_ | ||
| #define GRAPH_H_ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| class Graph { | ||
| struct vert_neigh { | ||
| int name; | ||
| double lenght; | ||
|
|
||
| vert_neigh(int name, double lenght) : name{name}, lenght{lenght} {} | ||
| }; | ||
|
|
||
| public: | ||
| // { {0, 1}, {1, 0}, {2, 3}, {2, 4}, {2, 5} } | ||
| Graph(int verts_num, std::initializer_list<std::pair<int, int>> links) { | ||
| adjacents = std::vector<std::vector<vert_neigh>>(verts_num, | ||
| std::vector<vert_neigh>()); | ||
| for (auto pair : links) { | ||
| adjacents[pair.first].push_back(vert_neigh(pair.second, 1.)); | ||
| } | ||
| } | ||
|
|
||
| // { {{0, 1}, lenght1}, {{1, 0}, lenght2}, ... } | ||
| Graph(int verts_num, | ||
| std::initializer_list<std::pair<std::pair<int, int>, double>> links) { | ||
| adjacents = std::vector<std::vector<vert_neigh>>(verts_num, | ||
| std::vector<vert_neigh>()); | ||
| for (auto pair : links) { | ||
| adjacents[pair.first.first].push_back( | ||
| vert_neigh(pair.first.second, pair.second)); | ||
| } | ||
| } | ||
|
|
||
| int size() { return adjacents.size(); } | ||
|
|
||
| void add_vert() { adjacents.push_back({}); } | ||
|
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. имена методов не по кодстайлу |
||
|
|
||
| friend std::ostream& operator<<(std::ostream& os, const Graph& g) { | ||
| os << " { "; | ||
| for (int i = 0; i < g.adjacents.size(); ++i) { | ||
| for (auto p : g.adjacents[i]) { | ||
| os << "{ {" << i << ", " << p.name << "}, " << p.lenght; | ||
| os << "}, "; | ||
| } | ||
| } | ||
| os << "}"; | ||
| return os; | ||
| } | ||
|
|
||
| void see_vertical() { | ||
| int vert_name = -1; | ||
| for (auto vert : adjacents) { | ||
| vert_name++; | ||
| if (vert.size() == 0) { | ||
| std::cout << vert_name << std::endl; | ||
| continue; | ||
| } | ||
| for (auto link_to : vert) { | ||
| std::cout << vert_name << " -> " << link_to.name | ||
| << ", lenght:" << link_to.lenght << std::endl; | ||
| } | ||
| } | ||
| } | ||
| std::vector<std::vector<vert_neigh>> adjacents; | ||
| }; | ||
|
|
||
| #endif | ||
Oops, something went wrong.
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.
хотяб VertNeighbour