Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <ctime>
- #include <string>
- #include <time.h>
- #include <chrono>
- using namespace std;
- void Print(int* arr, int size) {
- for (int i = 0; i < size; i++) {
- cout << arr[i] << "\t";
- }
- }
- void Otsev(int* a, int& n)
- {
- int j = 0;
- for (int i = 0; i < n; ++i)
- if (a[i] % 2 == 0)
- a[j++] = a[i];
- n = j;
- }
- void sortByInserts(int* arr, int N) {
- int buff = 0;
- int i, j;
- for (i = 1; i < N; i++)
- {
- buff = arr[i];
- for (j = i - 1; j >= 0 && arr[j] > buff; j--)
- arr[j + 1] = arr[j];
- arr[j + 1] = buff;
- }
- }
- int main()
- {
- srand((unsigned)time(0));
- setlocale(0, "");
- int size = 0;
- cout << "Введiть розмiр масиву: ";
- cin >> size;
- int* arr = new int[size];
- int elementId = -1;
- for (int i = 0; i < size; i++) {
- arr[i] = rand() % 27 - 90;
- }
- int index = 0;
- Print(arr, size);
- cout << endl;
- auto start1 = chrono::high_resolution_clock::now();
- for (int i = 4; i < size; i += 5) {
- arr[i] = 0;
- }
- auto finish1 = chrono::high_resolution_clock::now();
- cout << "Час замiни на 0: " << chrono::duration_cast<chrono::duration<double>>(finish1 - start1).count() << " секунд\n\n";
- Print(arr, size);
- auto start2 = chrono::high_resolution_clock::now();
- Otsev(arr, size);
- auto finish2 = chrono::high_resolution_clock::now();
- cout << "\nЧас вилучення непарних елементiв: " << chrono::duration_cast<chrono::duration<double>>(finish2 - start2).count() << " секунд\n\n";
- cout << endl;
- Print(arr, size);
- cout << endl;
- auto start3 = chrono::high_resolution_clock::now();
- sortByInserts(arr, size);
- auto finish3 = chrono::high_resolution_clock::now();
- cout << "Час сортування: " << chrono::duration_cast<chrono::duration<double>>(finish3 - start3).count() << " секунд\n\n";
- Print(arr, size);
- cout << endl;
- delete[] arr;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment