zoukankan      html  css  js  c++  java
  • 二叉树与结点,深度相关

    3)分别求二叉树的叶结点,度数为1的结点,度数为2的结点。

    #include "stdafx.h"
    #include<iostream>
    using namespace std;
    typedef struct BTreeNode
    {
    	float data;
    	char optr;
    	struct BTreeNode *lchild,*rchild;
    }BTree;
    int _tmain(int argc, _TCHAR* argv[])
    {
    	return 0;
    }
    int n0,n1,n2;//全局变量,用于统计结点数
    void Count(BTree *t)
    {
    	if(t)//前序遍历
    	{
    		if(t->lchild&&t->rchild)
    		{
    			n2++;
    		}
    		else if(t->lchild&&!t->rchild||!t->lchild&&t->rchild)
    		{
    			n1++;
    		}
    		else n0++;
    		if(t->lchild)Count(t->lchild);
    		if(t->rchild)Count(t->rchild);
    	}
    }
    

     4)求二叉树深度

    #include "stdafx.h"
    #include<iostream>
    using namespace std;
    typedef struct BTreeNode
    {
    	float data;
    	char optr;
    	struct BTreeNode *lchild,*rchild;
    }BTree;
    int _tmain(int argc, _TCHAR* argv[])
    {
    	return 0;
    }
    int Height(BTree *bt)
    {
    	int hl,hr;
    	if(bt==NULL)
    	{
    		return 0;
    	}
    	else
    	{
    		hl=Height(bt->lchild);
    		hr=Height(bt->rchild);
    		if(hl>hr)return (hl+1);
    		else return (hr+1);
    	}
    }
    
  • 相关阅读:
    ionic:安装
    ionic:ionic 教程
    ORM-Draper-DbConnectionManipulator:return new {}
    ionic:目录
    ionic:temple
    开发框架-手机应用:ionic
    CSS3:CSS3 文本效果
    CSS3:CSS3 渐变(Gradients)
    CARP-VRRP-HSRP
    java实现输入日期
  • 原文地址:https://www.cnblogs.com/tgkx1054/p/2622417.html
Copyright © 2011-2022 走看看