formatting
This commit is contained in:
@@ -164,6 +164,7 @@ public:
|
|||||||
Line(const Point &a_, const Point &b_) : a(a_),b(b_) {}
|
Line(const Point &a_, const Point &b_) : a(a_),b(b_) {}
|
||||||
Point a,b;
|
Point a,b;
|
||||||
};
|
};
|
||||||
|
|
||||||
double compute_slope(const Point &a, const Point &b) throw(int) {
|
double compute_slope(const Point &a, const Point &b) throw(int) {
|
||||||
double rise = b.y - a.y;
|
double rise = b.y - a.y;
|
||||||
double run = b.x - a.x;
|
double run = b.x - a.x;
|
||||||
@@ -174,14 +175,17 @@ return rise / run;
|
|||||||
double slope(const Line &ln) {
|
double slope(const Line &ln) {
|
||||||
return compute_slope(ln.a,ln.b);
|
return compute_slope(ln.a,ln.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool steeper_slope(const Line &m, const Line &n) {
|
bool steeper_slope(const Line &m, const Line &n) {
|
||||||
double slope_m = slope(m);
|
double slope_m = slope(m);
|
||||||
double slope_n = slope(n);
|
double slope_n = slope(n);
|
||||||
return slope_m > slope_n;
|
return slope_m > slope_n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void organize(std::vector<Line> &lines) {
|
void organize(std::vector<Line> &lines) {
|
||||||
std::sort(lines.begin(),lines.end(), steeper_slope);
|
std::sort(lines.begin(),lines.end(), steeper_slope);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
std::vector<Line> lines;
|
std::vector<Line> lines;
|
||||||
/* omitting code to initialize some data */
|
/* omitting code to initialize some data */
|
||||||
@@ -210,6 +214,7 @@ virtual const char* what() const throw() {
|
|||||||
return "My exception happened";
|
return "My exception happened";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
myexception myex;
|
myexception myex;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user