Advertisement
Guest User

stackoverflow hierarchy question.

a guest
Aug 23rd, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement