iiiclude# iiicludeusing namespace std;class tree{public:int data;class tree};tvpedef class tree node;tvpedef node *btree;btiee creat_tiee(btree.iiit);void pre(btree);void m(btiee);void post(btiee);iiit mam(void){int an[]={ 12,34,4,46,46,6,46,4,4,5,6}; btiee ptr=NULL;coutvv” [原始数组内容]',«endl; fbr(int i=0;idata=\ral;newnode->left=NULL;newnode->nght=NULL; if(root==NULL)iroot=newnode;retuni root;}elseifor(cuiTent=root;cunent!=NULL;) {backup=cuiTent;if(cunent->data>val) cunent=cunent->left;elsecunent=cunent->nght;}if(backup->data>val) backup->left=newnode;elsebackup->right=newnode;}return root;}void pre(btree ptr){if(ptr !=NULL)icout«M[H«senv(2)«ptr->data«H]H; pre(ptr->left);pre(ptr->right);}}void in(btiee pti){if(ptr!=NULL)im(ptr->left);cout«M[H«senv(2)«ptr->data«H]H; m(ptr->iight);}}void post(btree pti)if(ptr!=NULL)post(ptr->left);post(ptr->iight);cout«,,[H«senv(2)«ptr->data«H]H;}} 运行结果::\Docu>ent s and Sett ingsVAdainist rat or\桌面'Debug\树.exe*[原始数组内容][HL 21L341L 41L461L461L 61L461L 41L 41L 5][HL 21L341L 41L 61L 41L 41L 5 ] [46 ] [46 ] [46 ]中序遍历结果[HL 21L 41L 41L 41L 51L 6] L34] L46] L46] L46]后序遍历结果[51L 41L 41L 61L 4]L46]L46]L46]L34] L 21L 1]情按任意键继续• • •可根据实际情况改动!。