#include #include #include using namespace std; const int N = 24; // Liczebność zbioru. // Program główny //--------------- int main() { int d[N],i,j,x; cout << "Sortowanie przez wstawianie\n"; // Najpierw wypełniamy tablicę d[] liczbami pseudolosowymi d[0] = 21; d[1] = 1; d[2] = 2; d[3] = 52; d[4] = 896; d[5] = 13; d[6] = 312; d[7] = 543; d[8] = 999; d[9] = 666; d[10] = 68; d[11] = 69; d[12] = 26; d[13] = 98; d[14] = 67; d[15] = 28; d[16] = 18; d[17] = 10; d[18] = 4; d[19] = 89; d[20] = 4; d[21] = 98; d[22] = 1000; d[23] = 131; // PRZED Sortujemy printf ("\n \nPRZED SORTOWANIEM: \n"); for(i = 0; i < N; i++) { cout << d[i]; printf (", "); } printf ("\n\n-------------------------------------------------------- \nPO SORTOWANIU: \n"); // Sortujemy for(j = N - 2; j >= 0; j--) { x = d[j]; i = j + 1; while((i < N) && (x > d[i])) { d[i - 1] = d[i]; i++; } d[i - 1] = x; } // Wyświetlamy wynik sortowania for(i = 0; i < N; i++) { cout << d[i]; printf (", "); } cout << endl; system("PAUSE"); return 0; }