Skip to content

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 25, 2025

No description provided.

bool operator==(const Stack& other) const;
bool operator!=(const Stack& other) const;
private:
int m_null_value = 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.

это не соответствует условию, в каждом экземпляре класса хранится лишнее поле, не хорошо

int m_null_value = 0;
size_t m_begin = 0;
size_t m_end = 0;
size_t m_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.

лишние поля, можно было обойтись 2, ну иликак минимум без m_null_value

int m_last() const;
};

size_t RingBuffer::m_check_zero_size(const size_t size) const {
Copy link
Contributor Author

@18thday 18thday Jan 22, 2026

Choose a reason for hiding this comment

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

методы должны иметь имя в стиле методов, а не полей

}

RingBuffer::RingBuffer(size_t size) {
m_buffer.reserve(m_check_zero_size(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.

это должно бытыть в списке инициализации

m_buffer.reserve(m_check_zero_size(size));
for (size_t i = 0; i < Capacity(); ++i) {
m_buffer.push_back(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.

это лишний цикл, у вектора есть соответствующий конструктор, и корректней использовать список инициалзиации

m_buffer.reserve(1);
}
m_size = m_buffer.size();
m_end = m_buffer.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.

аналогично, список инициализации

m_copy_core(other);
}

inline void RingBuffer::m_push_back_core(const int item) {
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 лишняя пометка

if (Full()) {
return false;
}
else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лишняя вложенность, else не нужно писать, выше в условие есть return

pop_value = m_buffer[m_begin];

m_pop_core();

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.

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

  • не используются список инициализации в полной мере
  • лишнии ручные копирования вместо конструкторов
  • лишняя вложенность с else
  • много кода при формировании вектора в RingBuffer
  • метод Resize в RingBuffer с лишними копированиями
  • не оптимальное сравнение с безусловным копированием двух Queue


void RingBuffer::Pop() {
if (Size() == 0)
return;
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 в подобных случаях использовался стиль с {}
в данном случае не стиль

for (size_t i = 0; i < Size(); ++i) {
vector_buffer.push_back(m_buffer[i]);
}
}
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::vector<int> new_buffer;
new_buffer.reserve(new_size);

std::vector<int> vector_buffer = 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.

второе копирование зачем? не оптимально, несколько раз перекладываем элементы в разные контейнеры

bool operator==(const Queue& other) const;
bool operator!=(const Queue& other) const;
private:
int m_null_value = 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.

лишняя память в каждом экземпляре

while (!vector.empty()) {
m_output.push_back(vector.back());
vector.pop_back();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

а зачем мы принимаем по копии и потом ещё раз перекладываем элементы и к тому же из vector который ничей делаем pop_back

}
}

Queue::Queue(std::vector<int> 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.

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

m_output.push_back(m_input.back());
m_input.pop_back();
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

эту операцию можно вынести в приватный метод

Queue::Queue(std::initializer_list<int> ilist) {
for (const int v : ilist) {
m_input.push_back(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.

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


bool Queue::operator==(const Queue& other) const {
std::vector<int> this_merged = m_merge_vectors(m_input, m_output);
std::vector<int> other_merged = m_merge_vectors(other.m_input, other.m_output);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

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