📄 bitree.cpp
字号:
#include <stdlib.h>
#include <stdio.h>
#define queuesize 100
#define null 0
typedef int datatype;
typedef struct node{
datatype data;
node *lchild;
node *rchild;
}bintnode;
typedef bintnode *bintree;//定义二叉链表指针类型
void pre( bintree & phead)
{
if(phead)
{
printf("%d->", phead->data);
pre(phead->lchild);
pre(phead->rchild);
}
}
void swaplr( bintree &phead)
{
bintree tmp;
if(phead)
{
tmp = phead->lchild;
phead->lchild = phead->rchild;
phead->rchild = tmp;
swaplr(phead->lchild);
swaplr(phead->rchild);
}
}
void deleteall( bintree &phead)
{
if(phead)
{
deleteall(phead->lchild);
deleteall(phead->rchild);
free(phead);
phead = NULL;
}
}
void main()
{
bintree t = null;
bintree b, c, d, e;
t = (bintree)malloc(sizeof(struct node));
t->data = 1;
t->lchild = NULL;
t->rchild = NULL;
b = (bintree)malloc(sizeof(struct node));
b->data = 2;
b->lchild = NULL;
b->rchild = NULL;
c = (bintree)malloc(sizeof(struct node));
c->data = 3;
c->lchild = NULL;
c->rchild = NULL;
d = (bintree)malloc(sizeof(struct node));
d->data = 4;
d->lchild = NULL;
d->rchild = NULL;
e = (bintree)malloc(sizeof(struct node));
e->data = 5;
e->lchild = NULL;
e->rchild = NULL;
t->lchild = b;
t->rchild = c;
b->lchild = d;
b->rchild = e;
pre(t);
printf("\n");
swaplr(t);
pre(t);
deleteall(t);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -