数据结构与算法实验报告(5).doc
数据结构与算法实验报告(5)实验人: 学号: 时间:2015.5.20实验名称:交换左右子树实验原理:本实验是按先序遍历输入一棵二叉树, 再按先序遍历、中序遍历、后序遍历将其打印出来,交换所有左右子树, 最后再按先序遍历、中序遍历、后序遍历将其打印出来. 实验过程记录:template<class Type>bool ChangeBrunch(BinaryNode<Type> *&T) /交换所有左右子树if(T)BinaryNode<Type> *S;S = T->left;T->left = T->right;T->right = S;ChangeBrunch(T->left);ChangeBrunch(T->right);return true;void main(void)BinaryNode<char> *T = 0;cout << "请输入字符, 0 为结束: " << endl;CreateTree(T); /先序遍历输入一棵二叉树,cout << "先序遍立原树: " << endl; if(T != 0) T->PrintPreOrder();cout << endl;cout << "中序遍立原树: " << endl; if(T != 0) T->PrintInOrder();cout << endl;cout << "后序遍立原树: " << endl; if(T != 0) T->PrintPostOrder();cout << endl; ChangeBrunch(T);cout << "先序遍立原树: " << endl; if(T != 0) T->PrintPreOrder();cout << endl;cout << "中序遍立原树: " << endl; if(T != 0) T->PrintInOrder();cout << endl;cout << "后序遍立原树: " << endl; if(T != 0) T->PrintPostOrder();cout << endl;实验过程中的问题: 实验结果报告与实验总结:用0表示空子树. 一组实验结果为: 请输入字符, 0 为结束:abdhq00r00is00t00eju00v00l00cfm00n00go00p00先序遍立原树: a b d h q r i s t e j u v l c f m n g o p先序遍立原树: a b d h q r i s t e j u v l c f m n g o p先序遍立原树: a b d h q r i s t e j u v l c f m n g o p先序遍立新树: a c g p o f n m b e l j v u d i t s h r q先序遍立新树: a c g p o f n m b e l j v u d i t s h r q先序遍立新树: a c g p o f n m b e l j v u d i t s h r qPress any key to continue思考与疑问: