-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.c
More file actions
88 lines (71 loc) · 1.29 KB
/
program.c
File metadata and controls
88 lines (71 loc) · 1.29 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Do not modify this file.
Make all of your changes to main.c instead.
*/
#include "program.h"
#include <stdio.h>
#include <stdlib.h>
static int compare_bytes( const void *pa, const void *pb )
{
int a = *(char*)pa;
int b = *(char*)pb;
if(a<b) {
return -1;
} else if(a==b) {
return 0;
} else {
return 1;
}
}
void focus_program( char *data, int length )
{
int total=0;
int i,j;
//int mySum = 0;
srand48(38290);
for(i=0;i<length;i++) {
data[i] = 0;
}
for(j=0;j<100;j++) {
int start = lrand48()%length;
int size = 25;
for(i=0;i<100;i++) {
data[ (start+lrand48()%size)%length ] = lrand48();
}
}
for(i=0;i<length;i++) {
total += data[i];
}
}
void sort_program( char *data, int length )
{
int total = 0;
int i;
// int mySum = 0;
srand48(4856);
for(i=0;i<length;i++) {
data[i] = lrand48();
// mySum += data[i];
}
qsort(data,length,1,compare_bytes);
for(i=0;i<length;i++) {
total += data[i];
}
// printf("sort result is %d\n",total);
// printf("My sum is %d\n", mySum);
}
void scan_program( char *cdata, int length )
{
unsigned i, j;
unsigned char *data = (unsigned char*) cdata;
unsigned total = 0;
for(i=0;i<length;i++) {
data[i] = i%256;
}
for(j=0;j<10;j++) {
for(i=0;i<length;i++) {
total += data[i];
}
}
// printf("scan result is %d\n",total);
}