-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.h
62 lines (53 loc) · 1.29 KB
/
tools.h
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
#ifndef TOOLS_H
#define TOOLS_H
#include<iomanip>
#include<string>
using namespace std;
template <class T>
string stringify(T x, int width=15, const char ch=' ')
{
std::ostringstream o;
if (!(o << setw(width)<<setfill(ch)<<x))
cerr<<"Bad coversion to string"<<endl;
return o.str();
}
template<class T>
void mysort(const vector<T> &eval, size_t ind[] , size_t n){
bool swapped;
for(size_t i=1; i<n; i++){
ind[i]=i;
}
ind[0]=0;
double val1, val2;
do{
swapped = false;
for(size_t i=1; i<n-1; ++i){
val1=eval[ind[i]].head->print_width;
val2=eval[ind[i+1]].head->print_width;
if (val1> val2){
swap( ind[i], ind[i+1] );
swapped = true;
}
}
--n;
}while (swapped);
}
class COffset
{
public:
COffset(double _t=0, double _b=0):top(_t),bottom(_b){}
double width(){return top+bottom;}
double top, bottom;
private:
};
template<class T>
class CLink
{
public:
explicit CLink(T *_h, int d=1, double im_d=1):head(_h),length(d), immune_distance(im_d){ }
int length;
T *head;
double immune_distance;
private:
};
#endif /* TOOLS_H */