-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selection sort.cpp
73 lines (57 loc) · 1.06 KB
/
Selection sort.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
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
69
70
71
72
73
#include <stdio.h>
#include "iostream"
#include <ctime>
using namespace std;
//#define size 1000
//int a[size];
int rand_seed=10;
/* from K&R
- produces a random number between 0 and 32767.*/
int rand()
{
rand_seed = rand_seed * 1103515245 + 12345;
return (unsigned int)(rand_seed / 65536) % 32768;
}
void selection_sort(int a[], int n)
{
int i, j, min, temp;
i=0;
while(i<n-1)
{
min = i;
j = i+1;
while(j<n)
{
if(a[j]<a[min])
{
min = j;
}
j++;
}
temp = a[min];
a[min] = a[i];
a[i] = temp;
i++;
}
}
int main()
{
int size;
unsigned t0, t1;
for(int k=1; k<=50; k++)
{
size = k*1000;
int a[size];
for(int i=0; i<size; i++)
{
a[i] = rand();
}
rand_seed=10;
t0=clock();
selection_sort(a,size);
t1 = clock();
double time = (double(t1-t0)/CLOCKS_PER_SEC);
cout << time << endl;
}
return 0;
}