-
Notifications
You must be signed in to change notification settings - Fork 278
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
Lab3 #983
base: master
Are you sure you want to change the base?
Lab3 #983
Conversation
что в голове было написал в векторе, не совсем понимаю как можно сделать так чтобы resize работал O(1) и при этом новые элементы были заполнены нормально без мусора |
Вот тут есть разбор: https://ru.algorithmica.org/cs/basic-structures/vector/ |
Lab3CPP/lab3.cpp
Outdated
@@ -0,0 +1,41 @@ | |||
#include "lab3.h" | |||
|
|||
vector<char> bfs(char start, unordered_map<char, vector<char>> graph) { |
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.
graph не стоит передавать по значению.
Lab3CPP/lab3.cpp
Outdated
char start; | ||
input >> start; | ||
|
||
unordered_map<char, vector<char>> graph; |
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.
Не хватает typedef для всех типов, которые описываются неоднократно.
LibraryCPP/queue.cpp
Outdated
delete queue; | ||
} | ||
|
||
void queue_insert(Queue *queue, Data data) | ||
{ | ||
vector_resize(queue->vector, vector_size(queue->vector) + 1); |
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.
Нужно реализовать кольцевой буфер. resize не нужен, когда в начале массива уже освободилось место.
Lab3CPP/lab3.cpp
Outdated
@@ -0,0 +1,41 @@ | |||
#include "lab3.h" | |||
|
|||
vector<Data> bfs(Data start, unordered_map<Data, vector<Data>>& graph) { |
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.
typedef для неоднократно используемых типов всё ещё нужны.
LibraryCPP/queue.cpp
Outdated
|
||
struct Queue | ||
{ | ||
Vector *vector; | ||
size_t first; | ||
size_t last; |
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.
last можно вычислять на основе first и size.
Lab3CPP/lab3.cpp
Outdated
@@ -0,0 +1,41 @@ | |||
#include "lab3.h" | |||
|
|||
vector<Data> bfs(Data start, Graph& graph) { |
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.
vector<Data>
тоже несколько раз используется
Lab3CPP/lab3.h
Outdated
@@ -11,6 +11,7 @@ | |||
using namespace std; | |||
|
|||
typedef unordered_map<Data, vector<Data>> Graph; | |||
typedef vector<Data> Vector; | |||
|
|||
vector<char> bfs(char start, unordered_map<char, vector<char>>& graph); | |||
vector<char> task(ifstream& input, int reactions); |
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.
А тут почему другие типы?
Принято.
Задано начальное вещество и список химических реакций, в которых оно превращается в другое вещество. Написать программу, использующую поиск в ширину, и выводящую список веществ, которые можно получить из исходного.