-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditional.cpp
More file actions
44 lines (38 loc) · 824 Bytes
/
Copy pathadditional.cpp
File metadata and controls
44 lines (38 loc) · 824 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
#include "additional.h"
int argmax(double **d, int len){
double Max = d[0][0];
int index = 0;
for(int i = 0; i < len; i++){
if(Max < d[i][0]){
Max = d[i][0];
index = i;
}
}
return index;
}
int partition( int *a, int l, int r){
int pivot, i, j, t;
pivot = a[l];
i = l; j = r+1;
while( 1){
do ++i;
while( a[i] <= pivot && i <= r )
;
do --j;
while( a[j] > pivot );
if( i >= j )
break;
t = a[i]; a[i] = a[j]; a[j] = t;
}
t = a[l]; a[l] = a[j]; a[j] = t;
return j;
}
void quickSort( int *a, int l, int r){
int j;
if( l < r ){
// divide and conquer
j = partition( a, l, r);
quickSort( a, l, j-1);
quickSort( a, j+1, r);
}
}