首页 新闻 搜索 专区 学院

递归算法与非递归算法的区别

0
悬赏园豆:20 [已解决问题] 解决于 2011-11-11 14:49
<table> <tbody> <tr> <td class="content"> <p><code class="cpp comments">就比如二叉树的遍历,如何根据递归算法写出非递归算法,他们各自的优缺点是什么?麻烦给我讲讲递归算法的思想。谢谢了!</code></p> <p><code class="cpp comments">//////////////////////////////////////////// </code></p> </td> </tr> </tbody> </table> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>02</code></td> <td class="content"><code class="cpp comments">//二叉树的遍历算法 递归算法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>03</code></td> <td class="content"><code class="cpp comments">//Author:Wang Yong&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>04</code></td> <td class="content"><code class="cpp comments">//Date: 2010.8.19&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>05</code></td> <td class="content"><code class="cpp comments">//////////////////////////////////////////// </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>06</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>07</code></td> <td class="content"><code class="cpp preprocessor">#include &lt;stdio.h&gt; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>08</code></td> <td class="content"><code class="cpp preprocessor">#include &lt;stdlib.h&gt; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>09</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>10</code></td> <td class="content"><code class="cpp keyword bold">typedef</code> <code class="cpp color1 bold">char</code> <code class="cpp plain">ElemType; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>11</code></td> <td class="content"><code class="cpp comments">/////////////////////////////////////////// </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>12</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>13</code></td> <td class="content"><code class="cpp comments">//定义树的结点类型 </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>14</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>15</code></td> <td class="content"><code class="cpp keyword bold">typedef</code> <code class="cpp keyword bold">struct</code> <code class="cpp plain">BNode&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>16</code></td> <td class="content"><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>17</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">ElemType data; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>18</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">struct</code> <code class="cpp plain">BNode *lchild,*rchild;&nbsp;&nbsp;&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>19</code></td> <td class="content"><code class="cpp plain">}; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>20</code></td> <td class="content"><code class="cpp comments">/////////////////////////////////////////// </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>21</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>22</code></td> <td class="content"><code class="cpp comments">//二叉树的创建 </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>23</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>24</code></td> <td class="content"><code class="cpp plain">BNode *CreatBitTree() </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>25</code></td> <td class="content"><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>26</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">BNode *p; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>27</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp color1 bold">char</code> <code class="cpp plain">c; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>28</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">scanf</code><code class="cpp plain">(</code><code class="cpp string">"%c"</code><code class="cpp plain">,&amp;c); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>29</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code><code class="cpp plain">(c == </code><code class="cpp string">'#'</code><code class="cpp plain">) p = NULL; </code><code class="cpp comments">//截止二叉树的建立&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>30</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">else</code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>31</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>32</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">p = (BNode *) </code><code class="cpp functions bold">malloc</code><code class="cpp plain">(</code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(BNode)); </code><code class="cpp comments">//申请结点空间&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>33</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">p-&gt;data = c; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>34</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">p-&gt;lchild = CreatBitTree(); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>35</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">p-&gt;rchild = CreatBitTree(); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>36</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">} </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>37</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">return</code>&nbsp; <code class="cpp plain">p; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>38</code></td> <td class="content"><code class="cpp plain">}&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>39</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>40</code></td> <td class="content"><code class="cpp comments">//////////////////////////////////////////// </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>41</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>42</code></td> <td class="content"><code class="cpp comments">//二叉树的先序遍历 </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>43</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>44</code></td> <td class="content"><code class="cpp keyword bold">void</code>&nbsp; <code class="cpp plain">PreOrderTraverse(BNode *p) </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>45</code></td> <td class="content"><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>46</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code><code class="cpp plain">(p != NULL) </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>47</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>48</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"%c*"</code><code class="cpp plain">,p-&gt;data); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>49</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">PreOrderTraverse(p-&gt;lchild); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>50</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">PreOrderTraverse(p-&gt;rchild); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>51</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">} </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>52</code></td> <td class="content"><code class="cpp plain">} </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>53</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>54</code></td> <td class="content"><code class="cpp comments">///////////////////////////////////////////// </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>55</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>56</code></td> <td class="content"><code class="cpp comments">//二叉树的中序遍历 </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>57</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>58</code></td> <td class="content"><code class="cpp keyword bold">void</code> <code class="cpp plain">InOrderTraverse(BNode *p) </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>59</code></td> <td class="content"><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>60</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code><code class="cpp plain">(p != NULL) </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>61</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>62</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">InOrderTraverse(p-&gt;lchild); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>63</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"%c*"</code><code class="cpp plain">,p-&gt;data); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>64</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">InOrderTraverse(p-&gt;rchild); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>65</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">} </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>66</code></td> <td class="content"><code class="cpp plain">} </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>67</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>68</code></td> <td class="content"><code class="cpp comments">//////////////////////////////////////////////&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>69</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>70</code></td> <td class="content"><code class="cpp comments">//二叉树的后序遍历 </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>71</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>72</code></td> <td class="content"><code class="cpp keyword bold">void</code> <code class="cpp plain">PostOrderTraverse(BNode *p) </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>73</code></td> <td class="content"><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>74</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">if</code><code class="cpp plain">(p != NULL) </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>75</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>76</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">PostOrderTraverse(p-&gt;lchild); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>77</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">PostOrderTraverse(p-&gt;rchild); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>78</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"%c*"</code><code class="cpp plain">,p-&gt;data); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>79</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">} </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>80</code></td> <td class="content"><code class="cpp plain">}&nbsp; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>81</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>82</code></td> <td class="content"><code class="cpp comments">///////////////////////////////////////////// </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>83</code></td> <td class="content"><code class="spaces">&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>84</code></td> <td class="content"><code class="cpp color1 bold">int</code> <code class="cpp plain">main() </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>85</code></td> <td class="content"><code class="cpp plain">{ </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>86</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">BNode *tree; </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>87</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">tree = CreatBitTree(); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>88</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">PreOrderTraverse(tree); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>89</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"\n"</code><code class="cpp plain">); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>90</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">InOrderTraverse(tree); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>91</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"\n"</code><code class="cpp plain">); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>92</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp plain">PostOrderTraverse(tree); </code></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>93</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"\n"</code><code class="cpp plain">); </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>94</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>&nbsp;</td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="number"><code>95</code></td> <td class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="cpp keyword bold">return</code> <code class="cpp plain">0; </code></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="number"><code>96</code></td> <td class="content"><code class="cpp plain">}</code></td> </tr> </tbody> </table> </div>
希望花开的主页 希望花开 | 初学一级 | 园豆:179
提问于:2010-11-26 12:55
< >
分享
最佳答案
0

递归简单的说就是方法调用方法本身,每次调用都缩小范围再将下次调用条件进行运算,直到满足结束条件为止。递归最大的缺点就是速度慢,影响程序效率,但是小的数据量还是表现的不明显,比如递归显示树形,这是最常用的。

收获园豆:20
勤劳的渔网工作者 | 小虾三级 |园豆:572 | 2010-11-26 22:40
其他回答(1)
0

递归的效率一般不高,但是递归比较符合人类的思维方式。

wang_yb | 园豆:3277 (老鸟四级) | 2010-11-26 14:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册