-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (56 loc) · 1.1 KB
/
main.cpp
File metadata and controls
68 lines (56 loc) · 1.1 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <omp.h>
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#define ndatos 5
using namespace std;
double cpu_time(void);
int main(void)
{
int vector[ndatos]= {0};
int key=0;
int i =0, j =0;
double x_ = 0.0;
double y_ = 0.0;
for(int c = 0; c < (ndatos); c++)
{
vector[c] = rand() % (ndatos);
cout <<vector[c]<< " ";
}
x_ = cpu_time();
#ifdef _OPENMP
x_ = omp_get_wtime();
#endif
for (j=1; j<ndatos; j++)
{
key= vector[j];
i= j-1;
while(i>-1 && vector[i]>key)
{
vector[i+1]= vector[i];
i=i-1;
}
vector[i+1]=key;
}
y_ = cpu_time();
#ifdef _OPENMP
y_ = omp_get_wtime();
#endif
cout<< y_<< endl;
cout<< "\nOrdenados:\n";
for(j=0; j<ndatos ; j++)
{
cout<<vector[j]<<" ";
}
cout<< "tardo " << x_ <<" segundos"<<endl;
cout<< "tardo " << y_ <<" segundos"<<endl;
cin.get();
return 0;
}
double cpu_time(void)
{
double value;
value = (double) clock () / (double) CLOCKS_PER_SEC;
return value;
}