Skip to content

Filippov homework4 - #37

Open
dmytrofilippov wants to merge 7 commits into
mainfrom
Filippov_homework4
Open

Filippov homework4#37
dmytrofilippov wants to merge 7 commits into
mainfrom
Filippov_homework4

Conversation

@dmytrofilippov

Copy link
Copy Markdown
Collaborator

No description provided.

@ghost

ghost commented Nov 4, 2020

Copy link
Copy Markdown

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

@GKuzzinshtern GKuzzinshtern left a comment

Copy link
Copy Markdown
Collaborator

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 даже в циклах. Цикл может разрастись и потом не догадаешься что означает индекс.

Comment thread problem1.cpp
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

почему в схожих функциях схожие аргументы, но с разными типами и модификаторами? Есть отличия в реализации?

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

Choose a reason for hiding this comment

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

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

Comment thread problem1.cpp

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

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

Choose a reason for hiding this comment

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

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

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

Comment thread problem1.cpp
Comment thread problem1.cpp
Comment thread problem1.cpp
}
}

int copy_array[Size_Array];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

аналогично строке 25

Comment thread problem1.cpp
Comment thread problem1.cpp
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

см стр 63

Comment thread problem1.cpp
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

стр 78

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

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

Choose a reason for hiding this comment

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

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

@GKuzzinshtern GKuzzinshtern left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp
std::cin >> var;
if (!std::cin || var < 0) {
std::cout << "incorrect input\n";
return;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner

Choose a reason for hiding this comment

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

что правда? там же есть разница в бите под знак

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

Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp
Comment thread problem1.cpp
Comment thread problem1.cpp Outdated
Comment thread problem1.cpp
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
Comment thread problem2.cpp Outdated
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