Conversation
|
👉 View analysis in DeepCode’s Dashboard | Configure the bot |
GKuzzinshtern
left a comment
There was a problem hiding this comment.
Прочитал только problem1.cpp
Из общего - постарайтесь именовать переменные более выразительно, чем i,j,k даже в циклах. Цикл может разрастись и потом не догадаешься что означает индекс.
| void fill_array_random(int *begin, const int *const end); | ||
| void fill_array_by_hand(int *begin, size_t *const end); | ||
| void bubble_sort(int *begin, int *const end); | ||
| void quick_sort(int *begin, int *end); |
There was a problem hiding this comment.
почему в схожих функциях схожие аргументы, но с разными типами и модификаторами? Есть отличия в реализации?
There was a problem hiding this comment.
да, там где реализация через числа - size_t, где все через указатели - int. Ну и соответственно, где значение изменяться не будет - const
There was a problem hiding this comment.
понял - для разнообразия :)
|
|
||
| size_t Size_Array{}; | ||
| std::cin >> Size_Array; | ||
| if (!std::cin || Size_Array < Lower_Scope || Size_Array > Upper_Scope) { |
There was a problem hiding this comment.
ИМХО не очень здорово сравнивать переменные разных типов без явного приведения (static_cast). Компилятор приведет их неявно и возможны варианты. Компилятор часто-густо выдает предупреждения при таких попытках. По идее, все сравниваемые значения можно было сделать одного типа.
There was a problem hiding this comment.
но ведь в обоих случаях беззнаковое целое, поэтому считаю сравнение корректным)
There was a problem hiding this comment.
интересно, что замутит компилятор, если SizeArray окажется больше, чем верхний предел Lower_Scope.... Наверное, приведет неявно uint16_t к size_t
| } | ||
| } | ||
|
|
||
| int copy_array[Size_Array]; |
There was a problem hiding this comment.
аналогично строке 25
| bubble_sort(copy_array, copy_array + Size_Array); | ||
| auto end1 = std::chrono::steady_clock::now(); | ||
| std::chrono::duration<double> elapsed_seconds1 = end1 - start1; | ||
| std::cout << "Bubble sort elapsed time: " << elapsed_seconds1.count() |
| void bubble_sort(int *begin, int *const end) { | ||
| if (begin == nullptr || end == nullptr) { | ||
| std::cout << "One of the argument is null\n"; | ||
| return; |
problem1.cpp
Outdated
| return; | ||
| } | ||
| bool swap = true; | ||
| for (int *i = end; i > begin && swap; --i) { |
There was a problem hiding this comment.
в части i > begin && swap не помешали бы скобочки, чтоб показать Ваши явные намерения
There was a problem hiding this comment.
да, возможно) спасибо за ревью!
GKuzzinshtern
left a comment
There was a problem hiding this comment.
Было немного времени, решил доделать ревью на Ваше 4 задание :)
| std::cin >> var; | ||
| if (!std::cin || var < 0) { | ||
| std::cout << "incorrect input\n"; | ||
| return; |
There was a problem hiding this comment.
а если Вы сразу попытаетесь из потока записать в unsigned int отрицательное число, то не будет !std::cin ?
There was a problem hiding this comment.
Я тоже так думал) но к сожалению !std::cin пропускает отрицательные uint
There was a problem hiding this comment.
что правда? там же есть разница в бите под знак
There was a problem hiding this comment.
я так и не понял в чем причина, но clang пропускал отрицaтельный uint
No description provided.