二叉树的基本操作
数据结构(实验C语言版) 二叉树的基本操作 一、实验目的 掌握二叉树链表的结构和二叉树的建立过程 掌握用递归方法实现二叉树遍历的操作 二、实验环境 硬件环境要求: PC机(单机) 使用的软件名称、版本号以及模块: VS2010或Visual C++ 6.0或Win-TC等。 三、实验内容 编写一个程序,实现二叉树的先序遍历、中序遍历和后序遍历的各种递归算法。并以下图所示的二叉树b给出求解结果。 四、实验要求 1、用 VS2010 工具创建文件或程序,输入代码后,进行编译运行或在控制台 执行。 2、观看程序运行结果,并根据结果进行思考,对程序进行修改和总结。 源代码 #include < iostream > #define maxsize 50 using namespace std ; class node { private : char data ; node * lchild ; node * rchild ; public : void createnode ( node * & , char * ) ; //先序遍历 void fnode ( node * b ) { if ( b != NULL ) { cout << b - > data ; fnode ( b - > lchild ) ; fnode ( b - > rchild ) ; } } //中序遍历