void select(int* a, int K, long double* movents, long double* compasion) { int i, j, k; int x; for (i = 0; i < K; i++) // i - номер текущего шага { k = i; x = a[i]; (*compasion)++; for (j = i + 1; j < K; j++) // цикл выбора наименьшего элемента if (a[j] < x) { k = j; x = a[j]; *compasion = *compasion + 2;// k - индекс наименьшего элемента } a[k] = a[i]; a[i] = x; (*movents)++; } } After sorting 10,000 elements, the number of movements also turned out to be 10,000; Is it really so? How to most accurately calculate the displacement and comparison?
movents(by the way, why ?? !!! did you make floating-point counters? !!) at the end of the cycle, of course - you can just immediately increase byK... Yes, and you have comparisons somehow strangely counted - an increase only if less, but then by 2 at once ... - Harry*moventsincreased by K regardless of everything else. - Enikeyschiklong long, but with a floating point - you will still start to lose this unit at certain values ... - Harry