-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtw3insertion.cpp
More file actions
52 lines (45 loc) · 910 Bytes
/
tw3insertion.cpp
File metadata and controls
52 lines (45 loc) · 910 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
#define max 1000
#define rep(i , start , end ) for(int i=start;i<=end;i++)
int A[max];
void Insertion(int n)
{
for(int i=1;i<n;i++)
{
int j = i-1;
int temp = A[i];
while(j>=0 && A[j] > temp)
{
A[j+1] = A[j];
j--;
}
A[j+1] = temp;
}
}
int main()
{
int n;
time_t s , e;
cout << "Enter the Number of Elements : ";
cin >> n;
int i;
cout << "Elements are : ";
rep(i , 0 , n-1){
A[i] = rand()%100;
cout << A[i] << "\t";
}
s = clock();
for(int i=0;i<100000;i++)
{
Insertion(n);
}
e=clock();
cout << "\nElements in sorted order is : ";
rep(i , 0 , n-1)
{
cout << A[i] << "\t";
}
double cpu_time = (double)(e-s)/CLK_TCK;
cout << endl << "Time : " << cpu_time << endl;
}