渴求完整的c 二叉树程序
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152#includeusing namespace std;struct tree{ int data; tree *left,*right;};class Btree{ static int n; static int m;public: tree *root; Btree() { root=NULL; } void create_Btree(int); void Preorder(tree *); //先序遍历 void inorder(tree *); //中序遍历 void Postorder(tree *); //后序遍历 void display1() {Preorder(root); coutdata=x; newnode->right=newnode->left=NULL; if(root==NULL) root=newnode; else { tree *back; tree *current=root; while(current!=NULL) { back=current; if(current->data>x) current=current->left; else current=current->right; } if(back->data>x) back->left=newnode; else back->right=newnode; }}int Btree::count(tree *p){ if(p==NULL) return 0; else return count(p->left) count(p->right) 1; //这是运用了函数嵌套即递归的方法。
}void Btree::Preorder(tree *temp) //这是先序遍历二叉树,采用了递归的方法。{ if(temp!=NULL) { coutdataleft); Preorder(temp->right); }}void Btree::inorder(tree *temp) //这是中序遍历二叉树,采用了递归的方法。
{ if(temp!=NULL) { inorder(temp->left); coutdataright); }}void Btree::Postorder(tree *temp) //这是后序遍历二叉树,采用了递归的方法。
{ if(temp!=NULL) { Postorder(temp->left); Postorder(temp->right); coutdataleft==NULL&&temp->right==NULL)return n =1; else { findleaf(temp->left); findleaf(temp->right); } return n; }}int Btree::findnode(tree *temp){ if(temp==NULL)return 0; else { if(temp->left!=NULL&&temp->right!=NULL) { findnode(temp->left); findnode(temp->right); } if(temp->left!=NULL&&temp->right==NULL) { m =1; findnode(temp->left); } if(temp->left==NULL&&temp->right!=NULL) { m =1; findnode(temp->right); } } return m;} int main(){ Btree A; int array[]={7,4,2,3,15,35,6,45,55,20,1,14,56,57,58}; int k; k=sizeof(array)/sizeof(array[0]); cout先序遍历序列: "中序遍历序列: "。
答:我也不懂,建议你到专业的网站去看下。详情>>
问:请教哈!!请教哈!!新年好!我嘛,是软件工程的学生,现在学C++,但是其他的一些...
答:新年好!首先,你必须了解计算机的组成和结构以及操作系统的运作原理,这是基础 如果你想学习开发多线程、WINDOWS应用、动态链接库、WINDOWS组件的话,建议...详情>>