Skip to content

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 25, 2025

No description provided.



class Stack {
public:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишнии отступы, для модификаторов как правило не делают отступ и следовательно все методы имеют лишний отступ

Choose a reason for hiding this comment

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

Как я понимаю, зависит от кодстайла
Поэтому не стал менять

data_.clear();
}
void Swap(Stack& other){
std::swap(this->data_, other.data_);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this-> не используют в данном случае

Choose a reason for hiding this comment

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

Мне лично так просто понятнее. Но как понимаю, не по кодстайлу
0ad4174

return true;
}
bool operator!=(const Stack& other) const{
return ! (*this==other);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

пробел после унарного оператора лишний

Choose a reason for hiding this comment

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

counter_ = 0;
pos_for_next_ = 0;
oldest_ = 0;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

правильнее использоватьсписок инициализации вместо тела конструктора

Choose a reason for hiding this comment

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

Есть reserve для data_, поэтому использовал классический конструктор

*iter = init_val;
}
pos_for_next_ = 0;
counter_ = size > 0 ? size : 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в данном случае аналогично, у вектора есть конструктор который может создать вектор нужного размера с нужным значением

Choose a reason for hiding this comment

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

Сделал через assign, так вектор уже существует
0ad4174

if (counter_ == size_) {
return false;
}
Push(val);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в данном методе дважды выполняется проверка counter_ == size_ в методе и в Push, можно переиспользовать код без дополнительных првоерок

Choose a reason for hiding this comment

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

3 общих строчки не стал уж выносить в общий метод

size_ = new_size;
data_ = new_data;
counter_ = new_counter;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

очень много кода получилось

size_t size_;
size_t pos_for_next_;
size_t oldest_;
size_t counter_;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

можно было обойтись количеством полей на 1-2 меньше

Choose a reason for hiding this comment

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

Да, наверное oldest_ можно было выразить через pos_for_next_ и counter_, например

in_.reserve(size);
}
Queue(std::vector<int> vector){
in_ = vector;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в списке инийиализации

Choose a reason for hiding this comment

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

Да, так проще
0ad4174

stack.pop();
}

std::reverse(temp.begin(), temp.end());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

почему сразу не складывать в out_? без лишних копирований

Choose a reason for hiding this comment

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

Согласен, так проще
0ad4174

in_.reserve(initList.size());
for (int val : initList) {
in_.push_back(val);
}
Copy link
Contributor Author

@18thday 18thday Jan 21, 2026

Choose a reason for hiding this comment

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

у вектора есть конструктор от класса список инициализации

Choose a reason for hiding this comment

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

Реально
0ad4174

else {
// Если есть нет, то с конца последнего
return out_.front();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

тернарный оператор, комментарии лишние

Choose a reason for hiding this comment

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

Упростил
0ad4174

in_.clear();
out_.clear();
in_.shrink_to_fit();
out_.shrink_to_fit();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

shrink_to_fit() - не принято делать, clear обычно не освобождает память

Choose a reason for hiding this comment

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

Согласен, size и без этого будет 0
0ad4174

void Swap(Queue& other){
std::swap(in_, other.in_);
std::swap(out_, other.out_);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишняя пустая строка

Choose a reason for hiding this comment

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

return false;
}
Queue one = *this;
Queue two = other;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это слишком неэффективно, устройство очереди известно, поэтому в данном случае копирование слишком дорого, его можно избежатьсравнив элементы

Choose a reason for hiding this comment

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

Для сравнения надо оба списка привести в один порядок, так как в одном списке часть элементов может быть в out_, а в другом в in_. Так как == должно работать в том числе с константными объектами, просто вызвать для них in_to_out не получается.
Сходу не вижу решения, как без создания нового списка с правильным порядком сравнить 2 таких структуры

}

bool operator!=(const Queue& other) const{
return ! (*this == other);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишний пробел

Choose a reason for hiding this comment

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

Согласен
0ad4174


protected:
std:: vector <int> in_{};
std:: vector <int> out_{};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это очень плохо, много лишних пробелов

Choose a reason for hiding this comment

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

Исправил
0ad4174

return ! (*this == other);
}

protected:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

зачем модификатор protected?

Choose a reason for hiding this comment

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

Какое-то legacy
0ad4174

std:: vector <int> in_{};
std:: vector <int> out_{};

void In_to_out(){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Разный стиль именования методов

Choose a reason for hiding this comment

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

Не понял, о чем речь
Все мои методы snake_case с большой буквы


out_.swap(new_out);
in_.clear();
in_.shrink_to_fit();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

зачем его обрезать?

Choose a reason for hiding this comment

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

Согласен, size и без этого будет 0
0ad4174

}

Phasor(double ampl, double angle, ExpTag tag){
(void)tag;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в С++ лучше [[maybe_unused]] в аргументах перед ExpTag tag, либо static_cast(tag)

Choose a reason for hiding this comment

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

Да, забыл что с-style лучше не использовать
0ad4174


Phasor& operator*=(Phasor& lhs, const Phasor& rhs) {
lhs.SetCartesian(lhs.Real() * rhs.Real() - lhs.Imag() * rhs.Imag(),
lhs.Real() * rhs.Imag() + lhs.Imag() * rhs.Real());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

выравнивание похало

Choose a reason for hiding this comment

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

Согласен
0ad4174

Copy link
Contributor Author

@18thday 18thday left a comment

Choose a reason for hiding this comment

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

@EugeniusMiroshnichenko по задачам на классы:

  • использование тело конструктора вместо списка инициализации
  • использование this->
  • неэффективно сравнение в Queue с копированием
  • неэффективный конструктор от стека в Queue
  • поправить стиль кода

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