#include "stdafx.h" #include #include #include #include #include #include #include #include using namespace std; int pos[100]; int pos_ind[100]; int neg[100]; int comp_bubble = 0, change_bubble = 0; int comp_select = 0, change_select = 0; int comp_insert = 0, change_insert = 0; int comp_shell = 0, change_shell = 0; void copy(int from[][100], int to[][100], int height, int width) { int i, j; for (i = 0; i= 0) { pos_ind[n] = j; pos[n] = a[j]; n++; } else { a[j - n] = a[j]; } } return n; } void restore(int a[], int width, int num_positives) // восстановление после выполнения предыдущего блока { int last_pos_ind = 0, next_pos_ind; int i, j = 0; for (i = 0; i= pos_ind[i]; j--) { a[j + 1] = a[j]; } a[pos_ind[i]] = pos[i]; } } void bubble_sorting(int a[100], int width) { int j, h = width - 1; int sorting_finished = 1; int temp; if (width <= 1) return; do { sorting_finished = 1; for (j = 0; j a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; sorting_finished = 0; change_bubble++; } } h--; } while (sorting_finished == 0); } void select_sorting(int a[100], int width) { int temp, smallest_ind, j, k; if (width <= 1) return; for (j = 0; j= 0; k--) { comp_insert++; if (temp >= a[k]) break; a[k + 1] = a[k]; a[k] = temp; change_insert++; } } } void shell_sorting(int a[100], int width) { int j, distance = width / 2, temp, sorting_finished = 0; if (width <= 1) return; do { if (distance == 1) sorting_finished = 1; for (j = 0; j a[j + distance]) { temp = a[j]; a[j] = a[j + distance]; a[j + distance] = temp; sorting_finished = 0; change_shell++; } comp_shell++; } if (distance>1) distance--; } while (sorting_finished == 0); } int main(int argc, char **argv) { setlocale(LC_ALL, "Russian"); srand(time(NULL)); int matrix[100][100]; int for_sorting[100][100]; double height_d, width_d; int height, width; int i, j; int n; cout << "Введите число строк\n"; cin >> height_d; cout << "Введите число столбцов\n"; cin >> width_d; if (height_d != (int)height_d || width_d != (int)width_d || height_d <= 0 || width_d <= 0) { cout << "Ошибка ввода\n"; return 0; } height = (int)height_d; width = (int)width_d; for (i = 0; i