Skip to content

YuriyKuznetsov_HomeWork5#44

Open
GKuzzinshtern wants to merge 4 commits intomainfrom
YuriyKuznetsov_HomeWork5
Open

YuriyKuznetsov_HomeWork5#44
GKuzzinshtern wants to merge 4 commits intomainfrom
YuriyKuznetsov_HomeWork5

Conversation

@GKuzzinshtern
Copy link
Collaborator

No description provided.


void revrot(std::string &inout_sStr, const unsigned int in_cuiPieceSize) {
if (in_cuiPieceSize == 0) {
inout_sStr.clear();
Copy link
Owner

Choose a reason for hiding this comment

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

а зачем чистить строку?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

так как сказано в задании, что если размер <= 0 вернуть пусто. Вот и чищу, что возвращаю

return;
}
if (inout_sStr.length() < in_cuiPieceSize) {
inout_sStr.clear();
Copy link
Owner

Choose a reason for hiding this comment

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

тоже самое

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ага. Так как длина куска больше длины строки. В задании сказано - чистить

return;
}
if (in_cuiPieceSize == 1) {
return;
Copy link
Owner

Choose a reason for hiding this comment

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

а тут не чистим

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

на счет размер == 1 в задании не сказано чтоб возвращать пусто. Но и манипуляции над строкой бессмысленны.

unsigned int uiCriterion{};
for (auto itPieceOfString = sPieceOfString.begin();
itPieceOfString != sPieceOfString.end(); ++itPieceOfString) {
if (!std::isdigit(*itPieceOfString)) {
Copy link
Owner

Choose a reason for hiding this comment

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

может это в начале сделать перед циклом? а то не понятно мы делаем resize строке, а потом проверяем символы этой строки.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

согласен, можно вынести проверку на то, что в составе строки только цифры в начало

inout_sStr.clear();
return;
}
std::string sOneChar{*itPieceOfString};
Copy link
Owner

Choose a reason for hiding this comment

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

а обьязательно создавать строку для одного символа?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

функция stoi принимает в качестве аргумента строку, а манипулировать дальше надо с каждым символом строки. Поэтому и было принято такое решение

}
size_t szNewLength{(inout_sStr.length() / in_cuiPieceSize) * in_cuiPieceSize};

inout_sStr.resize(szNewLength);
Copy link
Owner

Choose a reason for hiding this comment

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

а зачем это?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

в задании сказано "проигнорировать последний кусок если размер меньше чем sz". Вот и отбрасываю лишнее


void vPushFront(structList &in_oList, int in_iData) {
structNode *oNode =
new (structNode){}; // make "try" for catching allocation troubles
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
new (structNode){}; // make "try" for catching allocation troubles
new structNode{}; // make "try" for catching allocation troubles

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

промахнулся :)

Comment on lines +117 to +118
if (oCurrentNode == (GetLastEl(in_oList))) {
return bPopBack(in_oList);
Copy link
Owner

Choose a reason for hiding this comment

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

я думаю это тут не нужно. Вы добавляете оверхед по том что нужно пробежаться по всему листу а потом если это не последний элемент вы ему переставляете указатели. Думаю пробежка по всему листу явно не надо

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

да, возможно. Тогда нужно проконтроллировать на nullptr при дальнейшем переприсваивании указателей

structNode *oTempNode{oNode};
oNode = oTempNode->oPrev;
delete oTempNode;
}
Copy link
Owner

Choose a reason for hiding this comment

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

а зачем тут два раза бегать сначало в конец а потом в начало?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

идея была - удалять все с конца и потом явно удалить первый нод. Если начать удалять сначала, то мы теряем указатель на первый элемент и, если что-то пойдет не так и часть нод не удалится, то уже потенциально не сможем повторно удалить. При удалении с конца можно дописать возможность возвращения к удалению.

}
structNode *oNode{in_oList.oFirstNode};
while (oNode->oNext != nullptr) {
if (bEqual(oNodeToCheck, oNode)) {
Copy link
Owner

Choose a reason for hiding this comment

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

а для этого обьязательно делать отдельную функцию?

Copy link
Collaborator 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