Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //сортируем
- void SortBy(int arr[], int size, bool desc)
- {
- for (int i = 0; i < size; i++)
- for (int j = 0; j < size - 1 - i; j++)
- if (arr[j] > arr[j + 1] and desc)
- swap(arr[j], arr[j + 1]);
- else if (arr[j] < arr[j + 1] and !desc)
- swap(arr[j], arr[j + 1]);
- }
- void SortByInc(int arr[], int size)
- {
- SortBy(arr, size, true);
- }
- void SortByDec(int arr[], int size)
- {
- SortBy(arr, size, false);
- }
- //выбираем
- void (*Choise(int size))(int[],int)
- {
- if (size < 10)
- return SortByInc;
- else
- return SortByDec;
- }
- //Вспомогательные штуки
- void fillRandomValue(int arr[], int size, int max)
- {
- for (int i = 0; i < size; i++)
- arr[i] = rand() % max;
- }
- void show(int arr[], int size)
- {
- for (int i = 0; i < size; i++)
- cout << arr[i] << " ";
- cout << endl;
- }
- int main()
- {
- srand(time(0));
- int size = rand()%20 + 1;
- cout << size << endl << endl;
- int* DynamicArray = new int[size];
- fillRandomValue(DynamicArray, size, 100);
- void (*sort)(int[], int) = Choise(size);
- sort(DynamicArray, size);
- show(DynamicArray, size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement