#include <iostream>
#include <ctime>
using namespace std;
void Bubble_Sort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
swap(arr[j],arr[j+1]);
}
}
}
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
clock_t start = clock();
Bubble_Sort(arr, n);
clock_t end = clock();
cout << "Sorted array: ";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
double time_taken = double(end - start) / CLOCKS_PER_SEC * 1000;
cout <<endl << "Time taken to sort the array: " << time_taken << " ms" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3RpbWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIEJ1YmJsZV9Tb3J0KGludCBhcnJbXSwgaW50IG4pIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbiAtIDE7IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbiAtIGkgLSAxOyBqKyspIHsKICAgICAgICAgICAgaWYgKGFycltqXSA+IGFycltqICsgMV0pIHsKICAgICAgICAgICAgICAgIHN3YXAoYXJyW2pdLGFycltqKzFdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKICAgIGNvdXQgPDwgIkVudGVyIHRoZSBzaXplIG9mIHRoZSBhcnJheTogIjsKICAgIGNpbiA+PiBuOwogICAgaW50IGFycltuXTsKICAgIGNvdXQgPDwgIkVudGVyIHRoZSBlbGVtZW50cyBvZiB0aGUgYXJyYXk6ICI7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGNpbiA+PiBhcnJbaV07CiAgICB9CiAgICBjbG9ja190IHN0YXJ0ID0gY2xvY2soKTsKICAgIEJ1YmJsZV9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