Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- int main()
- {
- const int randBegin{ 10 };
- const int randEnd{ 99 };
- const int arrSize{ 10 };
- //Ctrl+ K + C - comment
- //Ctrl + K + U - uncomment
- int arr[arrSize]{ 6,1,4,2,8,9,11,3,2,1 };
- //int arr[arrSize]{ 1,2,3,4,5,6,7,8,9,10 };
- //int arr[arrSize]{};
- int copy{};
- //char arr[arrSize]{ 'a','w','f','z','q','l','a','p','a','c' };
- //char copy{};
- //srand(time(0));
- //for (int i{ 0 }; i < arrSize; ++i) { arr[i] = randBegin + (rand() % (randEnd - randBegin)); }
- for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
- for (int insertPos{ 1 }; insertPos < arrSize; ++insertPos)
- {
- for (int testInsPos{insertPos}; testInsPos > 0; --testInsPos)
- {
- if (arr[testInsPos] < arr[testInsPos - 1])
- {
- copy = arr[testInsPos];
- arr[testInsPos] = arr[testInsPos -1];
- arr[testInsPos - 1] = copy;
- for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
- }
- }
- }
- for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement