forked from msdohehrty/dsa555-s16
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.cpp
More file actions
37 lines (33 loc) · 670 Bytes
/
insert.cpp
File metadata and controls
37 lines (33 loc) · 670 Bytes
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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "timer.h"
using namespace std;
void InsertionSort(int arr[],int size){
int curr;
int i, j;
for(i=1;i<size;i++){
curr=arr[i];
for(j=i;j>0 && arr[j-1] > curr;j--){
arr[j]=arr[j-1];
}
arr[j]=curr;
}
}
int main(int argc, char* argv[]){
int size=atoi(argv[1]);
int* myarr=new int[size];
ofstream log("insert.log");
Timer stopwatch;
for(int i=0;i<size;i++){
myarr[i]=rand();
}
stopwatch.start();
InsertionSort(myarr,size);
stopwatch.stop();
cout << stopwatch.currtime() << endl;
for(int i=0;i<size;i++){
log <<myarr[i]<< endl;
}
return 0;
}