Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个简单的问题,我只是想知道在循环中递归调用该方法是否被认为是糟糕的风格。我知道人们会因为递归的时间和空间成本而遇到问题,所以我想循环和递归会被认为效率更低且成本更高。
并非如此 - 有时您必须这样做,例如在递归爬取树数据结构时:
public void crawl(TreeNode node) { TreeNode[] children = node.getChildren(); for(TreeNode child:children) { crawl(child); } }