Exemplo n.º 1
0
 // Private method for updating min/max on deletion
 private void updateMinMaxOnDeleteAndRebuild(TreeNode t) {
   if (t == null) return;
   if (t.left == null && t.right == null) {
     return;
   }
   if (t.left != null && t.right == null) {
     t.maxX = maximum(t.left.maxX, t, true);
     t.maxY = maximum(t.left.maxY, t, false);
     t.minX = minimum(t.left.minX, t, true);
     t.minY = minimum(t.left.minY, t, false);
     return;
   } else if (t.left == null && t.right != null) {
     t.maxX = maximum(t.right.maxX, t, true);
     t.maxY = maximum(t.right.maxY, t, false);
     t.minX = minimum(t.right.minX, t, true);
     t.minY = minimum(t.right.minY, t, false);
     return;
   } else { // Get max from all three nodes
     t.maxX = maximum(t, t.left.maxX, t.right.maxX, true);
     t.maxY = maximum(t, t.left.maxY, t.right.maxY, false);
     t.minX = minimum(t, t.left.minX, t.right.minX, true);
     t.minY = minimum(t, t.left.minY, t.right.minY, false);
     return;
   }
 } // End private updateMinMaxOnDelete() method
Exemplo n.º 2
0
 // Method to calculate the above boundary queries
 // This method is called whenever a new node is inserted
 private void updateMinMax(TreeNode t, TreeNode newNode) {
   if (t == null && newNode == null) return;
   if (t.maxX.p.x() < newNode.p.x()) t.maxX = newNode;
   if (t.maxY.p.y() < newNode.p.y()) t.maxY = newNode;
   if (t.minX.p.x() > newNode.p.x()) t.minX = newNode;
   if (t.minY.p.y() > newNode.p.y()) t.minY = newNode;
 }