>left);
? ? ? ? print_postorder(tree->right);
? ? ? ? printf("%d\n",tree->data);
? ? }
}
好啦!该有的函数都有啦;
我们该写测试函数啦;
int main(void)
{
? ? node * root;
? ? node * tmp;
? ? //int i;
? ? root = NULL;
? ? /* Inserting nodes into tree */
? ? insert(&root,9);
? ? insert(&root,4);
? ? insert(&root,15);
? ? insert(&root,6);
? ? insert(&root,12);
? ? insert(&root,17);
? ? insert(&root,2);
? ? printf("Pre Order Display\n");
? ? print_preorder(root);
? ? printf("In Order Display\n");
? ? print_inorder(root);
? ? printf("Post Order Display\n");
? ? print_postorder(root);
? ? /* Deleting all nodes of tree */
? ? deltree(root);
}
运行结果如下:
Pre Order Display
9
4
2
6
15
12
17
In Order Display
2
4
6
9
12
15
17
Post Order Display
2
6
4
12
17
15
9
Discussion
然后这个例子似乎太简单了!它没有对树进行查询的函数;也没有树的高度进行测量;但是,它的简洁是为了更加容易理解;可是呢!太简洁了,以至于我们都不知道为什么要把数据弄成树形结构;为什么,难道线性结构的数据还不能解决我们身边的问题吗?
这个问题,不知道大家有没有问过自己。反正我以前经常问自己;那么,为了让大家理解存在树形结构的数据的必要性;我们,设想要统计C语言的关键字在代码中出现的频率;我们会怎么做呢??(这个问题我会在另一篇文章讲解)
See Alson
http://www.thegeekstuff.com/2013/02/c-binary-tree/
Can we drop this masquerade