-
Notifications
You must be signed in to change notification settings - Fork 7
- #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
- #2
Conversation
|
Яку функцію ти не назвав би оптимальною? |
Now function return pointer to added value. And adding of new value is more efficiently
|
загалом. ти робиш копію рядка, а потім його розвертаєш. Лишній прохід по цілому рядку. |
1.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
думаю це варто випраивити, як і в інших файлах також
|
Звідки ви знаєте що використовується в strdup? в студентській реалізації так, повний обхід, в нормальній тільки strlen повністю обходить, а далі або memcpy або розгортання циклу і так далі, тобто оптимізації. На рахунок swap згоден. Якщо ж писати в C++ стилі взагалі краще використати std::swap :). На рахунок макросів - почитайте буст і сирци різних контейнерів, здивуєтеся що там є багато макросів. Або ж Qt почитайте, там теж багато. Звичайно в більшості випадків, в який використовують макроси студенти в С, в С++ краще їх замінювати const, inline, template (в моєму випадку теж краще було б inline використати) Якщо ж писати повністю в C++ стилі, то я зробив би так: #include static const char* str = "The string!"; int main () { std::reverse(result.begin(), result.end()); char* reverse_string = &result[0]; std::cout << "Original: " << str << std::endl; return 0; Дякую за критику. Завдяки ній і учимося :) |
|
Напевне зараз і закомічу такий варіант :) |
No description provided.