Skip to content

Мананов Данил#21

Open
18thday wants to merge 53 commits intopsds-cpp:mainfrom
Dsv9toy:main
Open

Мананов Данил#21
18thday wants to merge 53 commits intopsds-cpp:mainfrom
Dsv9toy:main

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 24, 2025

No description provided.

bool operator!=(const Stack& otherStack) const;


private:
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> buffer_;
size_t oldestElement_ = 0;
size_t indexNextElem_ = 0;
size_t currentCountElem_ = 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.

несколько громоздкие названия, данное можно заменить на size_

buffer_.resize(capacity);
oldestElement_ = 0;
indexNextElem_ = 0;
currentCountElem_ = 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.

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

buffer_[0] = initialValue;
indexNextElem_ = 1 % buffer_.capacity();
currentCountElem_ = 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.

это плохо, можно было в списке инициализации вызвать соответствуеющийконструктор вектора, а тут достаточно объемный код, но дае еслитак, лучшеизбавится от else и лишней вложенности и поставить внтруи if return

oldestElement_ = 0;
indexNextElem_ = 0;
currentCountElem_ = 0;
for (int value : init) Push(value); //Добавил range based, так как будто бы уютнее смотрится
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

indexNextElem_ = NextIndex(indexNextElem_);
} else {
buffer_[indexNextElem_] = value;
indexNextElem_ = NextIndex(indexNextElem_);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в каждой из ветвей есть общий код, дублирование

for (size_t i = 0; i < otherQueue.inputDat.size(); ++i) {
temp2.push_back(otherQueue.inputDat[i]);
}
return temp1 == temp2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

tempOutput.push_back(tempInput.back());
tempInput.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.

неэффективный метод с копированием

return outputDat.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.

методы Front неконсистенты между собой, используют разные подходы

Queue::Queue(std::initializer_list<int> initList) : inputDat(initList) {}

Queue::Queue(const std::stack<int>& stack) {
std::stack<int> temp = 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.

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

std::stack<int> temp = stack;
// Извлекаем элементы из стека в обратном порядке
while (!temp.empty()) {
inputDat.insert(inputDat.begin(), temp.top());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

производить вставку в начало вектора очень неэффективно, когда есть контейнер output

}

Phasor operator/(const Phasor& phasor, double scalar) {
Phasor result = phasor;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

может тогда Phasor принимать как копию?

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.

@Dsv9toy отметил следующие моменты, требующие исправления:

  • использование тела конструктора вместо списка инициализации
  • неэффективно сравнение в Queue с копированием
  • неэффектривный метод Front с копированием в 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.

3 participants