forked from msdohehrty/dsa555-s16
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble.cpp
41 lines (37 loc) · 885 Bytes
/
bubble.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "timer.h"
using namespace std;
void BubbleSort(int arr[],int size){
int tmp; /*used for swapping*/
int i;
int j;
for (i=0; i<size-1; i++) {
for (j=0; j<size-1-i; j++){
if (arr[j+1] < arr[j]) { /* compare the two neighbors */
tmp = arr[j]; /* swap a[j] and a[j+1] */
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
}
}
int main(int argc, char* argv[]){
int size=atoi(argv[1]);
int *myarr=new int[size];
Timer stopwatch;
ofstream log("bubblelog.txt");
for(int i=0;i<size;i++){
myarr[i]=rand();
}
stopwatch.start();
BubbleSort(myarr,size);
stopwatch.stop();
cout << stopwatch.currtime() << endl;
/*for(int i=0;i<size;i++){
log <<myarr[i]<< endl;
}*/
delete [] myarr;
return 0;
}