Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void display(int* begin, int* end, std::string message = "") {
- if (!message.empty())
- std::cout << message << std::endl;
- for (int* next = begin; next != end; next++)
- {
- std::cout << *next << std::endl;
- }
- }
- void sort(int* begin, int* end) {
- display(begin, end, "Before sorting");
- bool isSorted;
- int temp;
- int* right = nullptr;
- do
- {
- isSorted = true;
- for (int* left = begin; left != end; left++)
- {
- //bubble sort
- right = left;
- ++right;
- if (right != end) {
- if (*left > * right) {
- temp = *left;
- *left = *right;
- *right = temp;
- isSorted = false;
- }
- }
- }
- } while (!isSorted);
- display(begin, end, "After sorting");
- }
- int main() {
- int tab[5]{ 8,2,3,4,5 };
- sort(&tab[0], &tab[5]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement