Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f23a695
docs(graph_view): Add readme about the task
ShatunovEvgeniy Nov 10, 2023
116457d
chore(graph_view): Add default CMake file
ShatunovEvgeniy Nov 10, 2023
5b6ab52
feat(graph_view): Add operator<< for default structures
ShatunovEvgeniy Nov 10, 2023
dbb1c52
feat(graph_view): Add declarations of main classes
ShatunovEvgeniy Nov 10, 2023
70deeef
feat(graph_view): Add operators= and << for view classes
ShatunovEvgeniy Nov 10, 2023
1b8a6bd
chore(graph_view): Rename .h to .hpp
ShatunovEvgeniy Nov 10, 2023
487621b
chore(graph_view): Change include from .h to .hpp
ShatunovEvgeniy Nov 10, 2023
bd3d21f
chore(graph_view): Add default main.cpp file
ShatunovEvgeniy Nov 10, 2023
44fc6db
test(graph_view): Add tests for view classes
ShatunovEvgeniy Nov 10, 2023
97f229d
feat(topology_sort): Add Vertex class for graph
ShatunovEvgeniy Nov 12, 2023
bf9ff21
feat(vertex): Add number field for Vertex class
ShatunovEvgeniy Nov 12, 2023
0e185bf
feat(vertex): Change namespace to enum
ShatunovEvgeniy Nov 12, 2023
c0bb076
feat(vertex): Add method to change Vertex
ShatunovEvgeniy Nov 12, 2023
b5df347
feat(topology_sort): Add Graph class
ShatunovEvgeniy Nov 12, 2023
923b2e6
Merge branch 'DafeMipt213:main' into main
ShatunovEvgeniy Nov 26, 2023
7446f0b
style: Change classes' and functions' names
ShatunovEvgeniy Nov 26, 2023
fa5b00a
fix(CMake): Fix bug with lUtil
ShatunovEvgeniy Dec 1, 2023
b2d1c2d
feat(sort): Add topology sort
ShatunovEvgeniy Dec 1, 2023
35e5175
feat(task_2): Add initial files
ShatunovEvgeniy Dec 1, 2023
1b8a92a
feat(task_2): Add class of graph
ShatunovEvgeniy Dec 1, 2023
2198fcb
feat(task_3): Add class graph and algorithms
ShatunovEvgeniy Dec 1, 2023
3446683
chore(tasl_3): Delete unnecessary files
ShatunovEvgeniy Dec 1, 2023
906d68a
Merge branch 'DafeMipt213:main' into main
ShatunovEvgeniy Jan 3, 2024
6bb638d
fix(task_2): Change int to size_t, fix used_
ShatunovEvgeniy Jan 3, 2024
a65ed0f
test(task 2): Add tests
ShatunovEvgeniy Jan 3, 2024
c0f4551
feat(task_3): Add solution of task 3
ShatunovEvgeniy Jan 3, 2024
793cba8
test(task_3): Add a test for task 3
ShatunovEvgeniy Jan 3, 2024
cfb0ae2
feat(task_4): Add solution of task 4
ShatunovEvgeniy Jan 3, 2024
7fafab2
test(task_4): Add a test for task 4
ShatunovEvgeniy Jan 3, 2024
03f6244
feat(task 4): Add solution of task 4
ShatunovEvgeniy Jan 5, 2024
0ab9b3c
test(task 4): Add tests for task 4
ShatunovEvgeniy Jan 5, 2024
f84e6e2
feat(task 6): Add solution of task 6
ShatunovEvgeniy Jan 5, 2024
9c76975
test(task 6): Add a test for task 6
ShatunovEvgeniy Jan 5, 2024
2e5da2b
Update README.md
ShatunovEvgeniy Mar 12, 2026
3531f4c
Update README.md
ShatunovEvgeniy Mar 12, 2026
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(homeworks)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sandbox)
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sandbox)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/additional_tasks)

Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# Домашнее задание для 2 семестра алгоритмов и структур данных

### Для удобства можно пользоваться папкой lib, все файлы из этой папки будут подключаться к любой задаче

### Можно получить дополнительные баллы, если добавить интересные текстовые задачи. Необходимы текст задачи, решение и тесты.

### Можно получить дополнительные баллы, если добавить теорию в папку doc. Делается в отдельном ПР
37 changes: 37 additions & 0 deletions additional_tasks/graph_view/CMakeLists.txt
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)
10 changes: 10 additions & 0 deletions additional_tasks/graph_view/README.md
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>

Перевод осуществляется из любого представления в любое.
51 changes: 51 additions & 0 deletions additional_tasks/graph_view/src/container_couts.hpp
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;
}
183 changes: 183 additions & 0 deletions additional_tasks/graph_view/src/graph_view.cpp
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;

Copy link
Copy Markdown

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]

            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])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
for (size_t elem : unord_list[vec_index])
for (size_t const elem : unord_list[vec_index])

data_[vec_index][elem] = elem || elem == 0 ? true : false;

Copy link
Copy Markdown

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]

            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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
std::pair<size_t, size_t> pair = edge_list[index];
std::pair<size_t, size_t> const pair = edge_list[index];

size_t parent = pair.first;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 parent = pair.first;
size_t const parent = pair.first;

size_t child = pair.second;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 child = pair.second;
size_t const child = pair.second;

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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
std::pair<size_t, size_t> pair = edge_list[index];
std::pair<size_t, size_t> const pair = edge_list[index];

size_t parent = pair.first;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 parent = pair.first;
size_t const parent = pair.first;

size_t child = pair.second;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 child = pair.second;
size_t const child = pair.second;

size_t max_vertex = std::max(parent, child) + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
size_t max_vertex = std::max(parent, child) + 1;
size_t const max_vertex = std::max(parent, child) + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 context

additional_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;

Copy link
Copy Markdown

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]

        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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
std::pair<size_t, size_t> pair = list[index];
std::pair<size_t, size_t> const pair = list[index];

size_t parent = pair.first;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 parent = pair.first;
size_t const parent = pair.first;

size_t child = pair.second;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 child = pair.second;
size_t const child = pair.second;

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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
std::pair<size_t, size_t> pair = list[index];
std::pair<size_t, size_t> const pair = list[index];

size_t parent = pair.first;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 parent = pair.first;
size_t const parent = pair.first;

size_t child = pair.second;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 child = pair.second;
size_t const child = pair.second;

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])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
for(size_t child : list[parent])
for(size_t const child : list[parent])

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;
}
Loading