Skip to content

Homework 2#39

Open
dalnoboy75 wants to merge 17 commits intoAlgorithmsDafeMipt2024:mainfrom
dalnoboy75:homework-2
Open

Homework 2#39
dalnoboy75 wants to merge 17 commits intoAlgorithmsDafeMipt2024:mainfrom
dalnoboy75:homework-2

Conversation

@dalnoboy75
Copy link
Copy Markdown

No description provided.

Comment thread task_02/src/stack.hpp Outdated

#include <stack>
#include <vector>
struct Node {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше перенести эту структуру в сам класс стека

Comment thread task_02/src/stack.hpp Outdated

class Stack {
public:
struct Stack {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и тут лучше все-таки класс применить и наружу не светить Node, если исправишь будет чуть больше баллов за д.з.

Comment thread task_03/src/test.cpp
Comment thread task_04/src/heap.cpp Outdated

void Heap::SiftDown(int index) {
while (2 * index + 1 < heap_.size()) {
int l = 2 * index + 1, r = 2 * index + 2;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай 1 объявление 1 строчка?

Comment thread task_05/src/test.cpp
Comment thread task_06/src/order_stats.hpp
Comment thread task_06/src/order_stats.hpp
Comment thread task_05/src/qsort.hpp Outdated
#include <vector>

template <typename T>
int Partition(std::vector<T>& arr, int l, int r) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно унести в lib/src/util.hpp уберем дублирование кода)

Comment thread task_07/src/test.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил бы ещё тест с пустым деревом и попыткой удаления

Comment thread task_09/src/test.cpp
Comment thread task_02/src/stack.cpp Outdated
data_.pop();
return result;
Node* t = this->top_;
this->top_ = this->top_->prev_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай не будем использовать тут this, только усложняет чтение

Comment thread task_02/src/stack.hpp Outdated

private:
std::stack<int> data_;
Node* Top();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node это приватный тип, а Top публичный метод, довольно странно

Comment thread task_02/src/stack.hpp Outdated

private:
std::vector<int> data_;
Stack s_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай сделаем их приватными полями

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай еще нормальные имена дадим, не однобуквенные

Comment thread task_04/src/heap.cpp Outdated

void Heap::SiftDown(int index) {
while (2 * index + 1 < heap_.size()) {
int l = 2 * index + 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай по длинее имена переменных сделаем: left

Comment thread task_04/src/heap.cpp Outdated
while (2 * index + 1 < heap_.size()) {
int l = 2 * index + 1;
int r = 2 * index + 2;
int j = l;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и тут j не понятно что за переменная

Comment thread task_04/src/test.cpp
Comment thread task_05/src/qsort.hpp Outdated
#include <iostream>
#include <vector>

#include "../../lib/src/util.hpp"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а просто #include <util.hpp> не работает?

#include <vector>

template <class T>
int Partition(std::vector<T>& data, int l, int r) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а из util.hpp не получится использовать?

Comment thread task_06/src/order_stats.hpp Outdated
template <class T>
int Partition(std::vector<T>& data, int l, int r) {
std::srand(std::time(nullptr));
int pivotPos = l + std::rand() % (r - l);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pivot_pos

Comment thread task_07/src/tree.hpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по всему файлу: Node* n давай как-то не так коротко назовем?

Comment thread task_02/src/stack.cpp
Comment thread task_02/src/stack.hpp Outdated

private:
std::vector<int> data_;
Stack s_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай еще нормальные имена дадим, не однобуквенные

Comment thread task_04/src/heap.cpp
Comment thread task_03/src/test.cpp
ASSERT_EQ(TempUpDayCounter(std::vector<int>{5, 12, 4, 9, 5, 4, 2}),
(std::vector<int>{1, 0, 1, 0, 0, 0, 0}));
ASSERT_EQ(TempUpDayCounter(std::vector<int>{2, 6, 17, 7, 3, 4}),
(std::vector<int>{1, 1, 0, 0, 1, 0}));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

везде в ответах 0 или 1 давай еще добавим еще каких-нибудь чисел)

Comment thread task_04/src/heap.cpp Outdated
#include <vector>

void Heap::SiftUp(int index) {
while (heap_[index] < heap_[(index - 1) / 2]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я бы добавил еще index != 0
что бы было явно понятно что в отрицательные числа не пойдем (можно просто index > 0 еще более явно)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants