The method in JavaScript is:
findNode: function(root, w, h) {
if (root.used)
return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);
else if ((w <= root.w) && (h <= root.h))
return root;
else
return null;
}
this line in particular wont work in C#
return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);
This is my attempt at translating it but I could use a second opinion as to whether this will work or break the algorithm. Is there a better way that I’m missing?
private Node FindNode(Node node, Block block)
{
Node n;
if (node.used) // recursive case
{
// is this a good translation of the JavaScript one-liner?
n = FindNode(node.right, block);
if (n != null)
{
return n;
}
else
{
return FindNode(node.down, block);
}
}
else if ((block.width <= node.width) && (block.height <= node.height)) // Base case
{
return node;
}
else
{
return null;
}
}
would be the only change I would make