Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by Zeng ( 12 years ago )
template <int n> struct Int {
  static const int N = n;
};


template <typename CHILD,  typename V> struct Tree {
  typedef CHILD Left;
  typedef CHILD Right;
  typedef V Val;
};

struct TreeNIL {
  typedef TreeNIL Left;
  typedef TreeNIL Right;
  typedef TreeNIL Val;
};

typedef Tree<TreeNIL, Tree<TreeNIL, Tree<TreeNIL, Tree<TreeNIL, Tree<TreeNIL, TreeNIL, Int<4> >, Int<3> >, Int<2> >, Int<1> >, Int<0> > MyTree;

template <typename TREE> struct Height {
  typedef typename TREE::Left L;
  typedef typename TREE::Right R;
  static const int result = 1 + (Height<L>::result > Height<R>::result ? Height<L>::result : Height<R>::result);
};

template <> struct Height<TreeNIL> {
  static const int result = 0;
};

int main(void) {
  std::cout << Height<MyTree>::result << std::endl;
  return 0;
}

 

Revise this Paste

Parent: 70807
Children: 70810
Your Name: Code Language: