Skip to content

Homework 2 #39

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
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

dalnoboy75
Copy link

No description provided.

@@ -1,23 +1,23 @@
#pragma once

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

Choose a reason for hiding this comment

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

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


class Stack {
public:
struct Stack {
Copy link
Contributor

Choose a reason for hiding this comment

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

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


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

Choose a reason for hiding this comment

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

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

#include <vector>

template <typename T>
int Partition(std::vector<T>& arr, int l, int r) {
Copy link
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 уберем дублирование кода)

Copy link
Contributor

Choose a reason for hiding this comment

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

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

data_.pop();
return result;
Node* t = this->top_;
this->top_ = this->top_->prev_;
Copy link
Contributor

Choose a reason for hiding this comment

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

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


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

Choose a reason for hiding this comment

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

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

void Push(int value);
int Pop();
int GetMin();

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

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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


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

Choose a reason for hiding this comment

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

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

while (2 * index + 1 < heap_.size()) {
int l = 2 * index + 1;
int r = 2 * index + 2;
int j = l;
Copy link
Contributor

Choose a reason for hiding this comment

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

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

#include <iostream>
#include <vector>

#include "../../lib/src/util.hpp"
Copy link
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
Contributor

Choose a reason for hiding this comment

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

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

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
Contributor

Choose a reason for hiding this comment

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

pivot_pos

Copy link
Contributor

Choose a reason for hiding this comment

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

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

void Push(int value);
int Pop();
int GetMin();

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

Choose a reason for hiding this comment

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

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

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
Contributor

Choose a reason for hiding this comment

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

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

#include <vector>

void Heap::SiftUp(int index) {
while (heap_[index] < heap_[(index - 1) / 2]) {
Copy link
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