码迷,mamicode.com
首页 > 其他好文 > 详细

三种递归遍历二叉树

时间:2018-08-05 22:34:41      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:ret   lib   sea   clu   递归   post   arc   pos   bin   

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 typedef int ElementType;
 5 
 6 struct BinarySearchTreeNode
 7 {
 8     ElementType Element;
 9     struct BinarySearchTreeNode *Left;
10     struct BinarySearchTreeNode *Right;
11 };
12 
13 int BinarySearchTreePreOrder(struct BinarySearchTreeNode *TreeRoot)
14 {
15     if(TreeRoot!=NULL)
16     {
17         printf("%d\n",TreeRoot -> Element);
18         BinarySearchTreePreOrder(TreeRoot->Left);
19         BinarySearchTreePreOrder(TreeRoot->Right);
20     }
21     return 0;
22 }
23 
24 int BinarySearchTreeInOrder(struct BinarySearchTreeNode *TreeRoot)
25 {
26     if(TreeRoot!=NULL)
27     {
28         BinarySearchTreeInOrder(TreeRoot->Left);
29         printf("%d\n",TreeRoot -> Element);
30         BinarySearchTreeInOrder(TreeRoot->Right);
31     }
32     return 0;
33 }
34 
35 int BinarySearchTreePostOrder(struct BinarySearchTreeNode *TreeRoot)
36 {
37     if(TreeRoot!=NULL)
38     {
39         BinarySearchTreePostOrder(TreeRoot->Left);
40         BinarySearchTreePostOrder(TreeRoot->Right);
41         printf("%d\n",TreeRoot -> Element);
42     }
43     return 0;
44 }
45 
46 int main()
47 {
48 //    BinarySearchTreePreOrder(TreeRoot);
49 //    BinarySearchTreeInOrder(TreeRoot);
50     BinarySearchTreePostOrder(TreeRoot);
51     return 0;
52 }

 

三种递归遍历二叉树

标签:ret   lib   sea   clu   递归   post   arc   pos   bin   

原文地址:https://www.cnblogs.com/Asurudo/p/9427455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!