Practical tips debugging deep recursion?

前端 未结 8 1973
长情又很酷
长情又很酷 2021-02-13 06:33

I\'m working on a board game algorithm where a large tree is traversed using recursion, however, it\'s not behaving as expected. How do I handle this and what are you experience

8条回答
  •  爱一瞬间的悲伤
    2021-02-13 07:16

    I would normally unit-test such algorithms with one or more predefined datasets that have well-defined outcomes. I would typically make several such tests in increasing order of complexity.

    If you insist on debugging, it is sometimes useful to doctor the code with statements that check for a given value, so you can attach a breakpoint at that time and place in the code:

      if ( depth = X && item.id = 32) {
         // Breakpoint here
      }
    

提交回复
热议问题