C++ 二叉树的创建于遍历
头文件(bitree.hpp) 1 #pragma 2 #include<iostream> 3 #include<queue> 4 #include<vector> 5 #include<stack> 6 using namespace std; 7 struct TreeNode 8 { 9 int NodeData; 10 TreeNode *pLeft; 11 TreeNode *pRight; 12 TreeNode(int x) :NodeData(x), pLeft(NULL),pRight(NULL) {} 13 }; 14 class Mytree 15 { 16 public: 17 void insertTree(TreeNode* proot,int n) 18 { 19 20 } 21 void PreOrderno(TreeNode *T)//前序遍历,递归 22 { 23 if (!T) 24 return; 25 if (T) 26 { 27 cout << T->NodeData << endl; 28 PreOrderno(T->pLeft); 29 PreOrderno(T->pRight); 30 31 } 32 33 } 34 void PreOrder(TreeNode *T)//非递归,前序遍历 35 { 36 if (T ==