Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- // СОРТИРОВКА МЕТОДОМ ПУЗЫРЬКА
- int main() {
- setlocale(LC_ALL, "rus");
- int const N = 5;
- int a[N];
- srand(time(0));
- cout << " Изначальный массив ";
- for (int i = 0; i < N; i++) {
- a[i] = rand() % 21 - 10;
- cout << a[i] << " ";
- }
- bool f = true;
- for (int i = N; i > 0 && f; i--) {
- f = false;
- for (int j = 0; j < i - 1; j++)
- if (a[j] > a[j + 1]) {
- int k = a[j];
- a[j] = a[j+1];
- a[j+1] = k;
- f = true;
- }
- }
- cout << endl;
- cout << "Отсортирванный массив ";
- for (int i = 0; i < N; i++)
- cout << a[i] << " ";
- }
Add Comment
Please, Sign In to add comment