-
Notifications
You must be signed in to change notification settings - Fork 9
/
example_prog.c
64 lines (51 loc) · 954 Bytes
/
example_prog.c
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
struct student
{
char reg[10];
char name[10];
float cgpa;
};
void main()
{
int num;
for(int i=0; i<num; i++)
{
int ab = 5;
}
find_time(arr, num);
}
void find_time(struct student *arrr, int n1)
{
struct timespec start, end;
clock_gettime(CLOCK_REALTIME);
quicksort(arrr, 0, n1-1);
clock_gettime(CLOCK_REALTIME);
double startt1= start.tv_nsec/1000000.0;
double endt1= end.tv_nsec/1000000.0;
double difft1= (end.tv_sec-start.tv_sec)*1000.0+(end.tv_nsec-start.tv_nsec)/1000000.0;
}
void quicksort(struct student *stu, int l, int r)
{
if(l<r)
{
int s= partition(stu, l ,r);
quicksort(stu, l, s-1);
quicksort(stu, s+1, r);
}
}
int partition(struct student *a, int l, int r)
{
char p[10];
strcpy(p, a[l].reg);
struct student temp;
int i= l;
int j= r+1;
//swap(a[i].reg, a[j].reg);
temp= a[i];
a[i]= a[j];
a[j]= temp;
//swap(a[l].reg, a[j].reg);
temp= a[l];
a[l]= a[j];
a[j]= temp;
return j;
}