title: Modeling a Node in a RangeTree
body: <p>I am currently implementing a 2D Range Tree. I am having trouble coming up with a plausible model (in Java) for my Node class.</p>
  
  <p>A node in the tree may have any of the following: midrange value, right and left child pointer, subtree, data pointer and/or previous and next pointers.</p>
  
  <p>I have broken down the Node into three separate logical pieces </p>
  
  <ul>
  <li>a) Node with just midRange value - every node has a midRange</li>
  <li>b) Node with left, right and subtree points. This represents a non-leaf node.</li>
  <li>c) Not with next, prev and data pointers. This represents a leaf node.</li>
  </ul>
  
  <p>I tried applying Composite and Decorator patterns, but to no avail. 
  I tried making:    </p>
  
  <ol>
  <li>Node interface with all the possible getters/setters, i.e.: getMidRange, getLeft, getRight, setLeft, setRight, etc...</li>
  <li>Having two classes implement the interface: Node2D and LinkedNode (leaf node). Node2D did everything except keep the links to next and previous. While LinkedNode only kept links to next and previous.</li>
  </ol>
  
  <p>It works like that, but I was wandering if there is a nicer way of modeling this as a set of classes?</p>
  
  <p>EDIT: <strong>Range Tree</strong> (short info): In range trees - all data is stored in the Leaf nodes, and the tree is always balanced. Furthermore all leafs are at the same height. Also, the leaves are sorted, and linked together by a doubly linked list. Last, but not least, each non-leaf node has a subtree - which is also a range tree, but with the leaves sorted on next attribute (say <strong>y</strong> if original tree was sorted on <strong>x</strong>).</p>
  
  <p><img src="https://i.stack.imgur.com/wPDR2.jpg" alt="RangeTreeBreakdown"></p>