Загрузка данных


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <clocale>
#include <iomanip>
using namespace std;

void sortirovka(int a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (a[j] > a[j + 1])
            {
                int t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
}

void pechat(int a[], int n)
{
for (int i = 0; i < n; i++)
        cout << a[i] << " ";

    cout << endl;
}

int main()
{
    setlocale(LC_ALL, "Russian");
    srand(time(0));

    int razm[] = { 100, 1000, 10000, 100000 };

    for (int q = 0; q < 4; q++)
    {
        int n = razm[q];
        int* a = new int[n];

        for (int i = 0; i < n; i++)
            a[i] = rand() % 1000;

        if (n == 100)
        {
            cout << "Исходный массив:" << endl;
            pechat(a, n);
        }
clock_t nach = clock();

        sortirovka(a, n);

        double vremya = (double)(clock() - nach) / CLOCKS_PER_SEC;

        if (n == 100)
        {
            cout << "\nОтсортированный массив:" << endl;
            pechat(a, n);
            cout << endl;
        }

        cout << "Размер массива: " << n << endl;
        cout << "Время сортировки: " << fixed << setprecision(6)
            << vremya << " сек." << endl << endl;

        delete[] a;
    }

    return 0;
}