Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PovTor.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- using namespace std;
- int main()
- {
- const int Size = 10;
- int arr[Size] = {9,8,7,6,5,4,3,2,1,0};
- //vstavka
- //---
- for (auto i = 1; i < Size; i++)
- {
- int tmp = arr[i];
- int j = i - 1;
- while (j >= 0 && arr[j] > tmp)
- {
- arr[j + 1] = arr[j];
- arr[j] = tmp;
- j--;
- }
- }
- for (auto i = 0; i <Size; i++)
- {
- cout << arr[i] << endl;
- }
- //Bubble
- //---
- for (auto i = 0; i < Size - 1; i++)
- {
- for (auto j = 0; j < (Size - 1) - i; j++)
- {
- if (arr[j] > arr[j + 1])
- {
- int tmp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = tmp;
- }
- }
- }
- for (auto i = 0; i < Size; i++)
- {
- cout << arr[i] << endl;
- }
- }
Add Comment
Please, Sign In to add comment