-1

I'm trying to flip a quad tree about the vertical axis recursively, but without using a particular PL. In which case I've written the following, but I'm 100% it's not actually good, and I can't quite sure I understand it as well.

flip(quadtree) {
    if (singleNode)
        return quadtree
    else return formQuadTree(flip(NW(quadtree)), flip(NE(quadtree)), flip(SW(quadtree)), flip(SE(quadtree)))

Any suggestions?

kx5
  • 17
  • 2

1 Answers1

1

Replace:

formQuadTree(flip(NW(quadtree)),flip(NE(quadtree)),flip(SW(quadtree)),flip(SE(quadtree))).

With:

formQuadTree(flip(NE(quadtree)),flip(NW(quadtree)),flip(SE(quadtree)),flip(SW(quadtree))).

What exactly don't you understand?

formQuadTree( topLeft, topRight, bottomLeft, bottomRight ) - forms your quad tree. Every time you enter recursively into flip( quadTree ) you go deeper and deeper inside the inductive step and return the base case, flipping each node that has 4 children quadTrees.

So once all your recursive calls get to return quadtree, all your inductive nodes have been arranged correspondingly.

Andy
  • 49,085
  • 60
  • 166
  • 233