爱问知识人 爱问教育 医院库

渴求完整的c 二叉树程序

首页

渴求完整的c 二叉树程序


        

提交回答

全部答案

    2018-05-15 04:38:15
  •   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先序遍历序列: "中序遍历序列: "。
      

    刘***

    2018-05-15 04:38:15

类似问题

换一换

相关推荐

正在加载...
最新资料 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 175-194
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):