Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <time.h>
- #include <conio.h>
- using namespace std;
- const int N = 20;
- void babelkowe() {
- int d[N], i, j, L = 0;
- cout << "Przed sortowaniem:\n\n";
- srand((unsigned)time(NULL));
- for (i = 0; i < N; i++) d[i] = rand() % 100;
- for (i = 0; i < N; i++) cout << setw(4) << d[i];
- cout << endl;
- for (j = 0; j < N - 1; j++)
- for (i = 0; i < N - 1; i++)
- if (d[i] > d[i + 1]) {
- swap(d[i], d[i + 1]);
- L++;
- }
- cout << "Po sortowaniu:\n\n";
- for (i = 0; i < N; i++) cout << setw(4) << d[i];
- cout << endl;
- cout << "\nLiczba przebiegow " << L;
- }
- void wstawianie() {
- int d[N], i, j, x, L = 0;
- cout << "\nPrzed sortowaniem:\n\n";
- srand((unsigned)time(NULL));
- for (i = 0; i < N; i++) d[i] = rand() % 100;
- for (i = 0; i < N; i++) cout << setw(4) << d[i];
- cout << endl;
- 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++;
- L++;
- }
- d[i - 1] = x;
- }
- cout << "Po sortowaniu:\n\n";
- for (i = 0; i < N; i++) cout << setw(4) << d[i];
- cout << endl;
- cout << "\nLiczba przebiegow " << L;
- }
- int main()
- {
- babelkowe();
- // wstawianie();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement