zoukankan      html  css  js  c++  java
  • 二叉树—课上课后练(4

     1 #include <iostream>
     2 using namespace std;
     3 
     4 typedef char DataType;
     5 
     6 //二叉树数据结构 
     7 struct node
     8 {
     9     DataType info ; //存放结点数据 
    10     struct node *lchild , *rchild ; //指向左右孩子的指针 
    11 };
    12 
    13 typedef struct node *BiTree ;
    14 
    15 /*创建二叉树
    16   函数名:createBiTree
    17   参数:无
    18   返回值:二叉树根结点指针
    19   */
    20 BiTree createBiTree(void)
    21 {
    22     char ch ;
    23     BiTree  root ;
    24     cin>>ch ;
    25     if(ch == '#') root = NULL;
    26     else{
    27         root = new struct node ;
    28         root->info = ch ;
    29         root->lchild = createBiTree() ;
    30         root->rchild = createBiTree();
    31     }
    32     return root ;
    33 }
    34 
    35 void visit(BiTree T)
    36 {
    37     cout<<T->info ;
    38 }
    39 
    40 int countFullNode(BiTree root)
    41 {
    42     //请在此处填写代码,计算二叉树中满结点的个数
    43     /********** Begin **********/
    44    int nodes = 0;
    45 if(root == NULL)
    46 return 0;
    47 else if(root->lchild== NULL && root->rchild == NULL)
    48 return 0;
    49 else if(root->lchild == NULL && root->rchild!= NULL)
    50 nodes = countFullNode(root->rchild);
    51 else if(root->lchild != NULL && root->rchild == NULL)
    52 nodes = countFullNode(root->lchild);
    53 else
    54 nodes = 1+countFullNode(root->lchild) + countFullNode(root->rchild);
    55 return nodes;
    56     
    57     /*********** End-**********/
    58 }
    59 
    60 int main(void)
    61 {
    62     BiTree root = createBiTree();
    63     cout<<countFullNode(root) ;
    64 }
    View Code
  • 相关阅读:
    后端返回文件流 前端处理方法
    证书profile 申请
    uniapp 报错 签名不对 请检查签名是否与开放平台上填写的一致
    微信开放平台创建应用如何填写官网
    防抖和节流笔记二
    防抖和节流笔记一
    如何申请ios证书
    textarea 固定大小,滚动条,限制拖动,文字对齐
    根据角色获取用户组
    号码验证
  • 原文地址:https://www.cnblogs.com/jeseesmith/p/13817288.html
Copyright © 2011-2022 走看看