Skip to content

VictorovaHomework4_1 - #36

Open
yaroslava15 wants to merge 2 commits into
mainfrom
VictorovaHomework4
Open

VictorovaHomework4_1#36
yaroslava15 wants to merge 2 commits into
mainfrom
VictorovaHomework4

Conversation

@yaroslava15

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread VictorovaHomework4_1.cpp
#include <chrono>
#include <iostream>
#include <random>
#include <time.h>

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.

Suggested change
#include <time.h>
#include <сtime>

это позволяет понять что вы используете С библиотеки

Comment thread VictorovaHomework4_1.cpp
#include <time.h>
using namespace std::chrono;

void BubbleSort(int *begin, int *end) {

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.

а проверить что begin и end не nullptr

Comment thread VictorovaHomework4_1.cpp
using namespace std::chrono;

void BubbleSort(int *begin, int *end) {
for (end; end > begin; end--) {

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.

а если у меня такая ситуация

int array[5];
BubbleSort(array, array+5);

то в вашей реализации при разыменовании end я получу UB
в той имплиментации которой вы написали end это не есть часть массива, это некий признак который говорит что у вас конец массива, это просто как маркер его нельзя разыменовывать

Comment thread VictorovaHomework4_1.cpp
Comment on lines +11 to +12
int temp{};
temp = *p;

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.

Suggested change
int temp{};
temp = *p;
int temp {*p};

Comment thread VictorovaHomework4_1.cpp
Comment on lines +30 to +31
int temp{};
temp = *begin;

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.

Suggested change
int temp{};
temp = *begin;
int temp{*begin};

Comment thread VictorovaHomework4_1.cpp
std::mt19937 gen(time(0));
std::uniform_int_distribution<> uid(0, 50);
switch (ch) {
case (0):

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.

добавте вместо 0, именованую константу enum или constexpr

Comment thread VictorovaHomework4_1.cpp
}
break;
default:
std::cout << "Error" << std::endl;

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.

в случае error может выйти с приложения

Comment thread VictorovaHomework4_1.cpp
std::cout << std::endl << "Array after bubble sort" << std::endl;
for (int i = 0; i < size; i++) {
std::cout << arr[i] << "\t";
}

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.

в расчет времени не надо включать вывод массива на экран

Comment thread VictorovaHomework4_2.cpp
}
}
}
void Sort_d(double* arr, size_t size) {

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.

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

Comment thread VictorovaHomework4_1.cpp
<< "0-->for Random Input" << std::endl
<< "1--> for User Input" << std::endl;
std::cin >> ch;
std::mt19937 gen(time(0));

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.

лучше вместо нуля написать nullptr, т.к. функция time принимает указатель, это даст лучшую читабельность и будет понятно что там используется указатель

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