Сортировка

#include <iostream> #include <time.h> using namespace std; void inclusionSort(int *num, int size) { for (int i = 1; i < size; i++) { int value = num[i]; int index = i; while ((index > 0) && (num[index - 1] < value)) { num[index] = num[index - 1]; index--; } num[index] = value; } } int main() { int *a; int n; cout << "N="; cin >> n; a = new int[n]; srand(time(NULL)); for (int i = 0; i < n; i++) { a[i] = rand() % 201 - 100; } time_t t1 = clock(); inclusionSort(a, n); time_t t2 = clock(); cout << endl; for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl << t2 - t1; cin.get(); cin.get(); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.