-
Notifications
You must be signed in to change notification settings - Fork 17
Shatunov Evgeniy #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
f23a695
116457d
5b6ab52
dbb1c52
70deeef
1b8a6bd
487621b
bd3d21f
44fc6db
97f229d
bf9ff21
0e185bf
c0bb076
b5df347
923b2e6
7446f0b
fa5b00a
b2d1c2d
35e5175
1b8a92a
2198fcb
3446683
906d68a
6bb638d
a65ed0f
c0f4551
793cba8
cfb0ae2
7fafab2
03f6244
0ab9b3c
f84e6e2
9c76975
2e5da2b
3531f4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| # Домашнее задание для 2 семестра алгоритмов и структур данных | ||
|
|
||
| ### Для удобства можно пользоваться папкой lib, все файлы из этой папки будут подключаться к любой задаче | ||
|
|
||
| ### Можно получить дополнительные баллы, если добавить интересные текстовые задачи. Необходимы текст задачи, решение и тесты. | ||
|
|
||
| ### Можно получить дополнительные баллы, если добавить теорию в папку doc. Делается в отдельном ПР |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
|
|
||
| get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
| string(REPLACE " " "_" PROJECT_NAME ${PROJECT_NAME}) | ||
| project(${PROJECT_NAME} C CXX) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp") | ||
| file(GLOB_RECURSE lib_source_list "../lib/src/*.cpp" "../lib/src/*.hpp") | ||
| file(GLOB_RECURSE main_source_list "src/main.cpp") | ||
| file(GLOB_RECURSE test_source_list "src/*.cpp") | ||
| file(GLOB_RECURSE test_list "src/*test.cpp") | ||
|
|
||
| list(REMOVE_ITEM test_source_list ${main_source_list}) | ||
| list(REMOVE_ITEM source_list ${test_list}) | ||
|
|
||
| include_directories(${PROJECT_NAME} PUBLIC src) | ||
| include_directories(${PROJECT_NAME} PUBLIC ../lib/src) | ||
|
|
||
| add_executable(${PROJECT_NAME} ${source_list} ${lib_source_list}) | ||
|
|
||
| # Locate GTest | ||
| enable_testing() | ||
| find_package(GTest REQUIRED) | ||
| include_directories(${GTEST_INCLUDE_DIRS}) | ||
|
|
||
| # Link runTests with what we want to test and the GTest and pthread library | ||
| add_executable(${PROJECT_NAME}_tests ${test_source_list}) | ||
| target_link_libraries( | ||
| ${PROJECT_NAME}_tests | ||
| GTest::gtest_main | ||
| ) | ||
|
|
||
| include(GoogleTest) | ||
| gtest_discover_tests(${PROJECT_NAME}_tests) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Задача на перевод одного и того же графа в его различные представления | ||
|
|
||
| В качестве возможных вариантов хранения графа используются: | ||
|
|
||
| 1. Матрица смежности, основанная на двумерном bool векторе | ||
| 2. Лист смежности, основанный на двумерном size_t векторе | ||
| 3. Лист смежности, основанных на векторе из unordered_set<size_t> (то есть без повторения вершин) | ||
| 4. Список вершин, основанный на векторе пар <size_t, size_t> | ||
|
|
||
| Перевод осуществляется из любого представления в любое. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #pragma | ||
|
|
||
| #include <vector> | ||
| #include <algorithm> | ||
| #include <unordered_set> | ||
| #include <iostream> | ||
|
|
||
| template<class K,class V> | ||
| std::ostream& operator<< (std::ostream& ost, std::pair<K,V>& v) | ||
| { | ||
| ost << '[' << v.first << "," << v.second << ']'; | ||
| return ost; | ||
| } | ||
|
|
||
| template<class T> | ||
| std::ostream& operator<< (std::ostream& ost, const std::vector<T>& v) | ||
| { | ||
| ost << '['; | ||
| if(!v.empty()) | ||
| { | ||
| auto it = v.begin(); | ||
| ost << *it; | ||
| ++it; | ||
| while(it != v.end()) | ||
| { | ||
| ost << ',' << *it; | ||
| ++it; | ||
| } | ||
| } | ||
| ost << ']'; | ||
| return ost; | ||
| } | ||
|
|
||
| template<class T> | ||
| std::ostream& operator<< (std::ostream& ost, const std::unordered_set<T>& v) | ||
| { | ||
| ost << '{'; | ||
| if(!v.empty()) | ||
| { | ||
| auto it = v.begin(); | ||
| ost << *it; | ||
| ++it; | ||
| while(it != v.end()) | ||
| { | ||
| ost << ',' << *it; | ||
| ++it; | ||
| } | ||
| } | ||
| ost << '}'; | ||
| return ost; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,183 @@ | ||||||
| #include "graph_view.hpp" | ||||||
| #include "container_couts.hpp" | ||||||
|
|
||||||
| AdjacencyMatrix& AdjacencyMatrix::operator= (const AdjacencyListVec& vec_list) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| data_.resize(vec_list.size(), std::vector<bool>(vec_list.size())); | ||||||
| for (size_t vec_index = 0; vec_index < vec_list.size(); vec_index++) | ||||||
| for (size_t index = 0; index < vec_list[vec_index].size(); index++) | ||||||
| data_[vec_index][vec_list[vec_index][index]] = vec_list[vec_index][index] || vec_list[vec_index][index] == 0 ? true : false; | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| AdjacencyMatrix& AdjacencyMatrix::operator= (const AdjacencyListUnorderedSet& unord_list) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| data_.resize(unord_list.size(), std::vector<bool>(unord_list.size())); | ||||||
| for (size_t vec_index = 0; vec_index < unord_list.size(); vec_index++) | ||||||
| for (size_t elem : unord_list[vec_index]) | ||||||
|
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. warning: variable 'elem' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| data_[vec_index][elem] = elem || elem == 0 ? true : 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. warning: logical expression is always true [misc-redundant-expression] data_[vec_index][elem] = elem || elem == 0 ? true : false;
^ |
||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| AdjacencyMatrix& AdjacencyMatrix::operator= (const EdgeList& edge_list) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| size_t max_vertex{0}; | ||||||
| for (size_t index = 0; index < edge_list.size(); index++) | ||||||
| { | ||||||
| std::pair<size_t, size_t> pair = edge_list[index]; | ||||||
|
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. warning: variable 'pair' of type 'std::pair<size_t, size_t>' (aka 'pair<unsigned long, unsigned long>') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t parent = pair.first; | ||||||
|
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. warning: variable 'parent' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t child = pair.second; | ||||||
|
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. warning: variable 'child' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| max_vertex = std::max(max_vertex, std::max(parent, child) + 1); | ||||||
| } | ||||||
|
|
||||||
| data_.resize(max_vertex, std::vector<bool>(max_vertex)); | ||||||
|
|
||||||
| for (size_t index = 0; index < edge_list.size(); index++) | ||||||
| { | ||||||
| std::pair<size_t, size_t> pair = edge_list[index]; | ||||||
|
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. warning: variable 'pair' of type 'std::pair<size_t, size_t>' (aka 'pair<unsigned long, unsigned long>') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t parent = pair.first; | ||||||
|
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. warning: variable 'parent' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t child = pair.second; | ||||||
|
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. warning: variable 'child' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t max_vertex = std::max(parent, child) + 1; | ||||||
|
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. warning: variable 'max_vertex' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
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. warning: Value stored to 'max_vertex' during its initialization is never read [clang-analyzer-deadcode.DeadStores] size_t max_vertex = std::max(parent, child) + 1;
^Additional contextadditional_tasks/graph_view/src/graph_view.cpp:42: Value stored to 'max_vertex' during its initialization is never read size_t max_vertex = std::max(parent, child) + 1;
^ |
||||||
| data_[parent][child] = child || child == 0 ? true : 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. warning: logical expression is always true [misc-redundant-expression] data_[parent][child] = child || child == 0 ? true : false;
^ |
||||||
| } | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| AdjacencyListVec& AdjacencyListVec::operator= (const AdjacencyMatrix& matrix) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| data_.resize(matrix.size()); | ||||||
| for (size_t vertex = 0; vertex < matrix.size(); vertex++) | ||||||
| for (size_t index = 0; index < matrix.size(); index++) | ||||||
| if(matrix[vertex][index]) data_[vertex].push_back(index); | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| AdjacencyListVec& AdjacencyListVec::operator= (const AdjacencyListUnorderedSet& list) | ||||||
| { | ||||||
| AdjacencyMatrix matrix(3); | ||||||
| matrix = list; | ||||||
| *this = matrix; | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| AdjacencyListVec& AdjacencyListVec::operator= (const EdgeList& list) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| size_t max_vertex{0}; | ||||||
| for (size_t index = 0; index < list.size(); index++) | ||||||
| { | ||||||
| std::pair<size_t, size_t> pair = list[index]; | ||||||
|
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. warning: variable 'pair' of type 'std::pair<size_t, size_t>' (aka 'pair<unsigned long, unsigned long>') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t parent = pair.first; | ||||||
|
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. warning: variable 'parent' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t child = pair.second; | ||||||
|
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. warning: variable 'child' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| max_vertex = std::max(max_vertex, std::max(parent, child) + 1); | ||||||
| } | ||||||
| data_.resize(max_vertex); | ||||||
| for (size_t index = 0; index < list.size(); index++) | ||||||
| { | ||||||
| std::pair<size_t, size_t> pair = list[index]; | ||||||
|
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. warning: variable 'pair' of type 'std::pair<size_t, size_t>' (aka 'pair<unsigned long, unsigned long>') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t parent = pair.first; | ||||||
|
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. warning: variable 'parent' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| size_t child = pair.second; | ||||||
|
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. warning: variable 'child' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| data_[parent].push_back(child); | ||||||
| } | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| AdjacencyListUnorderedSet& AdjacencyListUnorderedSet::operator= (const AdjacencyMatrix& matrix) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| data_.resize(matrix.size()); | ||||||
| for (size_t vertex = 0; vertex < matrix.size(); vertex++) | ||||||
| for (size_t index = 0; index < matrix.size(); index++) | ||||||
| if(matrix[vertex][index]) data_[vertex].insert(index); | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| AdjacencyListUnorderedSet& AdjacencyListUnorderedSet::operator= (const AdjacencyListVec& list) | ||||||
| { | ||||||
| AdjacencyMatrix matrix(3); | ||||||
| matrix = list; | ||||||
| *this = matrix; | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| AdjacencyListUnorderedSet& AdjacencyListUnorderedSet::operator= (const EdgeList& list) | ||||||
| { | ||||||
| AdjacencyMatrix matrix(3); | ||||||
| matrix = list; | ||||||
| *this = matrix; | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| EdgeList& EdgeList::operator= (const AdjacencyMatrix& matrix) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| for (size_t vertex = 0; vertex < matrix.size(); vertex++) | ||||||
| for (size_t index = 0; index < matrix.size(); index++) | ||||||
| if(matrix[vertex][index]) data_.push_back(std::pair<size_t, size_t> (vertex, index)); | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| EdgeList& EdgeList::operator= (const AdjacencyListVec& list) | ||||||
| { | ||||||
| data_.clear(); | ||||||
| for(size_t parent = 0; parent < list.size(); parent++) | ||||||
| { | ||||||
| for(size_t child : list[parent]) | ||||||
|
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. warning: variable 'child' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| data_.push_back(std::pair<size_t, size_t>(parent, child)); | ||||||
| } | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
| EdgeList& EdgeList::operator= (const AdjacencyListUnorderedSet& list) | ||||||
| { | ||||||
| AdjacencyMatrix matrix(3); | ||||||
| matrix = list; | ||||||
| *this = matrix; | ||||||
| return *this; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| std::ostream& operator<< (std::ostream& ost, AdjacencyMatrix& matrix) | ||||||
| { | ||||||
| for (auto& vec : matrix.data_) | ||||||
| std::cout << vec << std::endl; | ||||||
| return ost; | ||||||
| } | ||||||
|
|
||||||
| std::ostream& operator<< (std::ostream& ost, AdjacencyListVec& list_vec) | ||||||
| { | ||||||
| size_t i = 0; | ||||||
| for (auto& vec : list_vec.data_) | ||||||
| std::cout << i++ << ":" << vec << std::endl; | ||||||
| return ost; | ||||||
| } | ||||||
|
|
||||||
| std::ostream& operator<< (std::ostream& ost, AdjacencyListUnorderedSet& list_unord_set) | ||||||
| { | ||||||
| for (auto& unord_set : list_unord_set.data_) | ||||||
| std::cout << unord_set << std::endl; | ||||||
| return ost; | ||||||
| } | ||||||
|
|
||||||
| std::ostream& operator<< (std::ostream& ost, EdgeList& edge_list) | ||||||
| { | ||||||
| for (auto& pair : edge_list.data_) | ||||||
| std::cout << pair << std::endl; | ||||||
| return ost; | ||||||
| } | ||||||
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.
warning: logical expression is always true [misc-redundant-expression]