问题描述
所以我一直在网上试图掌握递归的概念,就在我以为我理解它的时候。
我不安静了解下面的代码如何工作。它用于显示二叉树中的所有元素(Infix订单)。
有人可以将其分解并解释每一步。
提前致谢。
我的尝试:
So I have been around the net trying to grasp the concept of recursion, and just when I thought i had understood it.
I am not quiet able to understand how the piece of code below works. It is used to show all the elements in a binary tree (Infix order).
Can someone please break it down and explain each step.
Thanks in advance.
What I have tried:
void Infix(struct BinaryNode *root){
if(root){
Infix((root) -> left);
printf("%3d", (root) -> data);
Infix((root) -> right);
}
}
推荐答案
有人可以分解并解释每一步。
Can someone please break it down and explain each step.
不,使用调试器查看程序正在做什么,你将学到更多,更快。
当你不明白你的代码在做什么或为什么它做它的作用时,答案是调试器。
使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。
[]
[]
[]
调试器在这里向您展示您的代码在做什么你的任务是与它应该做的事情进行比较。
调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
No, use the debugger to see what the program is doing, you will learn much more and faster.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
这篇关于理解C中的递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!