Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <algorithm>
- using namespace std;
- void bubble(int *a, int n) {
- for (int i=n; i>=0; i--) {
- for (int j=0; j<i; j++) {
- if (a[j]>a[j+1]) {
- swap(a[j],a[j+1]);
- }
- }
- }
- }
- int main(int argc, char** argv) {
- int n;
- cin >> n;
- int a[n];
- for (int i=0; i<=n; i++) {
- a[i]=rand() % n;
- }
- unsigned start_time = clock();
- bubble(a,n);
- unsigned end_time = clock();
- for ( int i=0; i<=n; i++) {
- cout << " " << a[i];
- }
- cout << endl;
- cout << " Time: " << end_time-start_time << " mc " << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement