#include <bits/stdc++.h>
using namespace std;
void bubbleSort(vector<int>& arr) {
int n = arr.size();
bool swapped;
for (int i = 0; i < n - 1; i++) {
swapped = false;
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
swap(arr[j], arr[j + 1]);
swapped = true;
}
}
if (!swapped)
break;
}
}
void printVector(const vector<int>& arr) {
for (int num : arr)
cout << " " << num;
}
int main() {
vector<int> arr = { 64, 34, 25, 12, 22, 11, 90 };
clock_t begin = clock();
bubbleSort(arr);
clock_t end = clock();
cout << "Sorted array: \n";
printVector(arr);
cout<<"Time run: "<< fixed << (float)(end-begin)/CLOCKS_PER_SEC<<" s"<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIGJ1YmJsZVNvcnQodmVjdG9yPGludD4mIGFycikgewogICAgaW50IG4gPSBhcnIuc2l6ZSgpOwogICAgYm9vbCBzd2FwcGVkOwogIAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuIC0gMTsgaSsrKSB7CiAgICAgICAgc3dhcHBlZCA9IGZhbHNlOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbiAtIGkgLSAxOyBqKyspIHsKICAgICAgICAgICAgaWYgKGFycltqXSA+IGFycltqICsgMV0pIHsKICAgICAgICAgICAgICAgIHN3YXAoYXJyW2pdLCBhcnJbaiArIDFdKTsKICAgICAgICAgICAgICAgIHN3YXBwZWQgPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICghc3dhcHBlZCkKICAgICAgICAgICAgYnJlYWs7CiAgICB9Cn0KCnZvaWQgcHJpbnRWZWN0b3IoY29uc3QgdmVjdG9yPGludD4mIGFycikgewogICAgZm9yIChpbnQgbnVtIDogYXJyKQogICAgICAgIGNvdXQgPDwgIiAiIDw8IG51bTsKfQoKaW50IG1haW4oKSB7CiAgICB2ZWN0b3I8aW50PiBhcnIgPSB7IDY0LCAzNCwgMjUsIDEyLCAyMiwgMTEsIDkwIH07CiAgICBjbG9ja190IGJlZ2luID0gY2xvY2soKTsgCiAgICBidWJibGVTb3J0KGFycik7CiAgICBjbG9ja190IGVuZCA9IGNsb2NrKCk7IAogICAgY291dCA8PCAiU29ydGVkIGFycmF5OiBcbiI7CiAgICBwcmludFZlY3RvcihhcnIpOwogICAgY291dDw8IlRpbWUgcnVuOiAiPDwgZml4ZWQgPDwgKGZsb2F0KShlbmQtYmVnaW4pL0NMT0NLU19QRVJfU0VDPDwiIHMiPDxlbmRsOwogICAgcmV0dXJuIDA7Cn0K