Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

stackoverflow hierarchy question.

By: a guest on Aug 23rd, 2011  |  syntax: C#  |  size: 0.78 KB  |  views: 93  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. interface BinaryTree<TreeType, Node> {
  2.         Node left(TreeType t, Node node);
  3.         Node right(TreeType t, Node node);
  4. }
  5.  
  6. interface BinaryTreeWithRoot<TreeType, Node> : BinaryTree<TreeType, Node> {
  7.         Node root(TreeType t);
  8. }
  9.  
  10. interface BinaryTreeWithParentLink<TreeType, Node> : BinaryTree<TreeType, Node> {
  11.         Node parent(TreeType t, Node node);
  12. }
  13.  
  14. // Now an implementation of the Subtree.
  15.  
  16. // The subtree object won't be tied to a specific BinaryTree.
  17. class Subtree<Tree, TreeType, Node> : BinaryTreeWithRoot<TreeType, Node>, Tree
  18.         where Tree : BinaryTree<TreeType, Node> {
  19.        
  20.         // During initialization, initialize the root as a node from the tree.
  21.         public Subtree(Node root);
  22.         Node root;
  23.        
  24.         override BinaryTreeWithRoot<TreeType, Node>.root(TreeType t) {
  25.                 return this.root;
  26.         }
  27. }