-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandsort.c
More file actions
49 lines (43 loc) · 797 Bytes
/
randsort.c
File metadata and controls
49 lines (43 loc) · 797 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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define NUMELE 10000
void main()
{
int i,j,t;
clock_t startt,endt;
double totalt;
FILE *fpr;
int a[NUMELE];
startt=clock();
for(i=0;i<NUMELE;i++)
scanf("%d",&a[i]);
int pos;
for(i=0;i<NUMELE-1;i++){
pos=i;
for(j=i+1;j<NUMELE;j++)
{
if(a[pos]>a[j])
{
pos=j;
}
}
if(pos!=i)
{
t=a[i];
a[i]=a[pos];
a[pos]=t;
}
}
fpr=fopen("ascending.txt","w");
for(i=0;i<NUMELE;i++)
fprintf(fpr,"%d\n",a[i]);
fclose(fpr);
fpr=fopen("descending.txt","w");
for(i=NUMELE-1;i>=0;i--)
fprintf(fpr,"%d\n",a[i]);
fclose(fpr);
endt=clock();
totalt=(double)(endt-startt)/CLOCKS_PER_SEC;
printf("%lf",totalt);
}