当前位置: 动力学知识库 > 问答 > 编程问答 >

shape - Flipping QuadTree in recursive abstract code

问题描述:

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?

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: