📄 tree.cpp
字号:
// Tree.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include <iostream>
using namespace std;
typedef struct TreeNode
{
TreeNode * L;
TreeNode * R;
int data;
}TreeNode,*BT;
void IniTree(BT &T)
{
int d;
cin>>d;
if(d==0)
T=NULL;
else
{
T=(TreeNode *)malloc(sizeof(TreeNode));
T->data=d;
IniTree(T->L);
IniTree(T->R);
}
}
void Preorder(TreeNode *T)
{
if(T)
{
cout<<T->data;
Preorder(T->L);
Preorder(T->R);
}
}
void Depth(TreeNode *T,int h,int & depth)
{
if(T)
{
if(h>depth)
depth=h;
Depth(T->L,h+1,depth);
Depth(T->R,h+1,depth);
}
}
int main()
{
BT T;
IniTree(T);
//IniTree(T);
Preorder(T);
int h=1;
int depth=0;
Depth(T,h,depth);
cout<<depth;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -