Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include
- class Bound {
- public:
- Bound() : x0(0.0), x1(0.0) {};
- Bound(double x) : x0(x), x1(x) {};
- double width() const {return x1-x0;}
- void rebound(const Bound *a, const Bound *b);
- private:
- double x0, x1;
- };
- void Bound::rebound(const Bound *a, const Bound *b)
- {
- if (a && b) {
- x0=std::min(a->x0, b->x0);
- x1=std::max(a->x1, b->x1);
- }
- }
- class Node : public Bound {
- public:
- Node(double x) : Bound(x), left(0), right(0) {};
- Node(Node *a, Node *b) : left(a), right(b) {rebound();}
- void rebound() { rebound(left, right); }
- private:
- Node *left;
- Node *right;
- };
- int main() {
- Node A(1.0);
- Node B(2.0);
- Node C(&A, &B);
- }
- using Bound::rebound;
- void rebound() { rebound(left, right); }
- void rebound() { Bound::rebound(left, right); }
- void rebound(const Bound *a, const Bound *b) { Bound::rebound(a, b); };
- void rebound() { rebound(left, right); }
Add Comment
Please, Sign In to add comment