Skip to content

Filippov homework4#37

Open
dmytrofilippov wants to merge 7 commits intomainfrom
Filippov_homework4
Open

Filippov homework4#37
dmytrofilippov wants to merge 7 commits intomainfrom
Filippov_homework4

Conversation

@dmytrofilippov
Copy link
Collaborator

No description provided.

@ghost
Copy link

ghost commented Nov 4, 2020

Congratulations 🎉. DeepCode analyzed your code in 4.083 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

Copy link
Collaborator

@GKuzzinshtern GKuzzinshtern left a comment

Choose a reason for hiding this comment

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

Прочитал только 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);
Copy link
Collaborator

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.

да, там где реализация через числа - size_t, где все через указатели - int. Ну и соответственно, где значение изменяться не будет - const

Copy link
Collaborator

Choose a reason for hiding this comment

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

понял - для разнообразия :)


size_t Size_Array{};
std::cin >> Size_Array;
if (!std::cin || Size_Array < Lower_Scope || Size_Array > Upper_Scope) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ИМХО не очень здорово сравнивать переменные разных типов без явного приведения (static_cast). Компилятор приведет их неявно и возможны варианты. Компилятор часто-густо выдает предупреждения при таких попытках. По идее, все сравниваемые значения можно было сделать одного типа.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

но ведь в обоих случаях беззнаковое целое, поэтому считаю сравнение корректным)

Copy link
Collaborator

Choose a reason for hiding this comment

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

интересно, что замутит компилятор, если SizeArray окажется больше, чем верхний предел Lower_Scope.... Наверное, приведет неявно uint16_t к size_t

}
}

int copy_array[Size_Array];
Copy link
Collaborator

Choose a reason for hiding this comment

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

аналогично строке 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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

см стр 63

void bubble_sort(int *begin, int *const end) {
if (begin == nullptr || end == nullptr) {
std::cout << "One of the argument is null\n";
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

стр 78

problem1.cpp Outdated
return;
}
bool swap = true;
for (int *i = end; i > begin && swap; --i) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

в части i > begin && swap не помешали бы скобочки, чтоб показать Ваши явные намерения

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

да, возможно) спасибо за ревью!

Copy link
Collaborator

@GKuzzinshtern GKuzzinshtern left a comment

Choose a reason for hiding this comment

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

Было немного времени, решил доделать ревью на Ваше 4 задание :)

std::cin >> var;
if (!std::cin || var < 0) {
std::cout << "incorrect input\n";
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

а если Вы сразу попытаетесь из потока записать в unsigned int отрицательное число, то не будет !std::cin ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Я тоже так думал) но к сожалению !std::cin пропускает отрицательные uint

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.

я так и не понял в чем причина, но clang пропускал отрицaтельный uint

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