Skip to content

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Jan 14, 2026

No description provided.


std::ostream& operator<<(std::ostream& os, const Coord2D& coord) {
os << '(' << coord.x << ", " << coord.y << ')';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}

std::ostream& operator<<(std::ostream& os, const Circle& c) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

os << '+';
} else {
os << '-';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

тернарный оператор в строку лучще подойдет, да и все можно в одну строку

os << ',';
}

os << std::endl << '\t' << 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.

буфер тут излишне сбрасывать '\n' лучше подойдет

first = false;
}

os << std::endl <<"}";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

аналогично, сброс буфера лишний, ну и тут строковый литерал для одного символа лишний, тогда уже "\n}"


if (step > 0 && from > to) {
return range;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

можно 3 условия не писать


uniqueElem.reserve(v.size());


Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишние пустые строки

void Swap(Stack& other);

bool operator==(const Stack& other) const {
return this->stack_ == other.stack_;
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-> в данном случае и обычно лишнее

}
};

Queue(std::vector<int> v) : outputV_(v.rbegin(), v.rend()){};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишнее копирование, принимается копия вектора

outputV_.reserve(size);
};

Queue(const int size) {
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


Queue(std::initializer_list<int> list) : inputV_(list) {};

Queue(const size_t size) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

const излишне в таком контексте, поскольку принимаем копию и это конструктор класса, никто нам не мешает умножить size на два например и создать больший контейнер

outputV_.reserve(size);
};

inline void Push(int 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.

Ключевое слово inline применяется сейчас в другом контексте. В данном случае оно избыточно

return false;
}

return this->GetQueueAsVector() == other.GetQueueAsVector();
Copy link
Contributor Author

@18thday 18thday Jan 14, 2026

Choose a reason for hiding this comment

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

  • this лишний
  • создание полных копий для сравнения двух очередей, очень ресурсоемко данном случае

}

std::vector<int> Queue::GetQueueAsVector() const {
std::vector<int> result;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

размер известен заранее, можно избежать реалокаций


outputV_.pop_back();

return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

много лишних пустых строк

return outputV_.back();
}

const int& Queue::Front() const {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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


private:
std::vector<int> ringBuff_{};
size_t head_ = 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.

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


RingBuffer(size_t capacity) : ringBuff_(capacity > 0 ? capacity : 1), head_(0), tail_(0), size_(0) {}

RingBuffer(size_t capacity, const int iVal) : ringBuff_(capacity > 0 ? capacity : 1, iVal), head_(capacity), tail_(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.

лишний const в аргументах

RingBuffer(size_t capacity) : ringBuff_(capacity > 0 ? capacity : 1), head_(0), tail_(0), size_(0) {}

RingBuffer(size_t capacity, const int iVal) : ringBuff_(capacity > 0 ? capacity : 1, iVal), head_(capacity), tail_(0),
size_(capacity > 0 ? capacity : 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.

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

++size_;
} else {
// аналогично head
tail_ = (tail_ + 1) % ringBuff_.capacity();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

где-то ringBuff_.capacity(), где-то cap лучше приести к единообразию

}

bool RingBuffer::TryPop(int& val) {
if (size_ > 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.

лучше под if короткую ветвь использовать

ringBuff_[i] = tempV[i];
}

ringBuff_.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.

много лишнего в данном методе, лучше применить идиому copy and swap,
непонятно почему нужно резервировать временный вектор не под новый размер, а под минимальный, поему сразу не располагаются элементы нужным образом, а сначала добавляются в конец, а потом реверсивный порядок создается.
и зачем вызывается shrink_to_fit() после resize()?

v.reserve(size_);

for (size_t i = 0; i < size_; ++i) {
v.push_back(ringBuff_[(tail_ + i) % ringBuff_.size()]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ringBuff_.size() - корректнее все-таки capacity(), как минимум надо привести к единообразию

}

std::vector<int> RingBuffer::Vector() const {
std::vector<int> v;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

имена лучше длинее одной буквы

constexpr double EPS_ = 1e-12;
}


Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}

double RadToDeg(double rad){
return rad * 180 / M_PI;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

надо к единообразию привести, 180.0 и 180

class Phasor {
public:
Phasor() = default;
Phasor(double A, double rad) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A - плохое имя

}

// Сложение коммутативно
Phasor operator+(double rhs, const Phasor& lhs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

слева все-таки lhs справа rhs, можно было просто выразить через предыдущий оператор

return (lhs + (-rhs));
}


Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

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.

@notron124 отметил следующие моменты:

  • много оптимальных решений
  • хорошо читаемый, аккуратный код
  • внутри класса обычно не используют для вызова методов this->
  • в задачах классы встречаются лишние копирования, не понравился Resize() в кольцевом буфере

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