Skip to content

VictorovaHomework4_1#36

Open
yaroslava15 wants to merge 2 commits intomainfrom
VictorovaHomework4
Open

VictorovaHomework4_1#36
yaroslava15 wants to merge 2 commits intomainfrom
VictorovaHomework4

Conversation

@yaroslava15
Copy link
Collaborator

No description provided.

#include <chrono>
#include <iostream>
#include <random>
#include <time.h>
Copy link
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>

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

#include <time.h>
using namespace std::chrono;

void BubbleSort(int *begin, int *end) {
Copy link
Owner

Choose a reason for hiding this comment

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

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

using namespace std::chrono;

void BubbleSort(int *begin, int *end) {
for (end; end > begin; end--) {
Copy link
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 on lines +11 to +12
int temp{};
temp = *p;
Copy link
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 on lines +30 to +31
int temp{};
temp = *begin;
Copy link
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};

std::mt19937 gen(time(0));
std::uniform_int_distribution<> uid(0, 50);
switch (ch) {
case (0):
Copy link
Owner

Choose a reason for hiding this comment

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

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

}
break;
default:
std::cout << "Error" << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

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

std::cout << std::endl << "Array after bubble sort" << std::endl;
for (int i = 0; i < size; i++) {
std::cout << arr[i] << "\t";
}
Copy link
Owner

Choose a reason for hiding this comment

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

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

}
}
}
void Sort_d(double* arr, size_t size) {
Copy link
Owner

Choose a reason for hiding this comment

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

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

<< "0-->for Random Input" << std::endl
<< "1--> for User Input" << std::endl;
std::cin >> ch;
std::mt19937 gen(time(0));
Copy link
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

Comments