try to do some of qsort bitch include stdio include stdlib include tim

 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
// try to do some of qsort, bitch! :3
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct array {
int *data;
};
struct array flush( struct array info, int lenght );
struct array gnome( struct array info, int length );
void output( struct array info, int lenght );
void main(void) {
struct array list;
int i, len = 25;
srand(time(NULL));
//..int test[25];
//printf("%i\n", sizeof(test) / sizeof(test[0]));
list.data = malloc( sizeof(int) * len );
for (i=0; i < len; i++)
list.data[i] = i;
output(list, len);
list = flush(list, len);
output(list, len);
list = gnome(list, len);
output(list, len);
//in the end we must free dinamyc data
free(list.data); list.data = 0;
}
struct array flush( struct array info, int lenght ){
int i, random1, random2, number;
for (i=0; i<lenght*2; i++){
random1 = rand() % lenght;
random2 = rand() % lenght;
number = info.data[random1];
info.data[random1] = info.data[random2];
info.data[random2] = number;
}
return info;
}
struct array gnome( struct array info, int lenght ){
int i, j, x;
for (i=0; i<lenght; i++)
for (j=0; j<lenght; j++)
if (i != j)
if (info.data[i] < info.data[j]) {
x = info.data[i];
info.data[i] = info.data[j];
info.data[j] = x;
}
return info;
}
void output( struct array info, int lenght ){
int i;
for (i=0; i<lenght; i++)
printf("%i ", info.data[i]);
printf("\n");
}