二叉树(前中后序遍历) c++的第二章

今日任务:
打一遍二叉树(前中后序遍历)
c++的第二章全部学完
函数,指针复习

1.二叉树的前中后序遍历

#include<stdio.h>

#include<stdlib.h>

typedef struct Bitree

{

char data;

struct Bitree *lchild,*rchild;

}*BiTree,BiTNode;

BiTree t;

BiTree head;

BiTNode *   CreatTree()

{

BiTNode    * T;

char n;

scanf("%c",&n);

if(n==’#’)

T=NULL;

else

{

T=(BiTNode *)malloc(sizeof(BiTNode));

if(headNULL)

head=T;

T->data=n;

T->lchild=CreatTree();

T->rchild=CreatTree();

}

return T;//

}

void PreTree(BiTree T)

{

if(TNULL)

return;

printf("%c",T->data);

PreTree(T->lchild);

PreTree(T->rchild);

}

void InTree(BiTree T)

{

if(TNULL)

return;

InTree(T->lchild);

printf("%c",T->data);

InTree(T->rchild);

}

void PostTree(BiTree T)

{

if(TNULL)

return;

PostTree(T->lchild);

PostTree(T->rchild);

printf("%c",T->data);

}

int main()

{

head=NULL;

t=CreatTree();

PreTree(head);

printf("\n");

InTree(head);

printf("\n");

PostTree(head);

}
**`2.c++的第二章笔记`**`

```cpp
#include<iostream>
using namespace std//C++输入和输出的工具(即使用cin和cout时一定要用iostream

在这里插入图片描述换行可用
cout<<endl;
cout<<"\n";
库函数sqrt()需在#include<cmath>或者#include<math.h>
计算5的8次方用x=pow(5.0,8.0);函数原型为下:

double pow(double,double)

rand()函数在cstdlib或stdlib的头文件中,该函数用于:去随机整数。
原型:`int rand(void)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值