📄 t.c
字号:
/*2004.5.12*/
/*version 1.02
____A____
/ \
/ \
D E
__/ \_ / \
/ \ R H
P S \
/ / \ N
T G L
上面这棵二叉树在数据文件中的存放形式:
A~D~P{T!S~G!L!E~R!H}N!
*/
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <Tree2.h>
#include <buildtree.h>
#include <visit1.h>
#include <visit2.h>
#define LEFT 0 /*变量steering取值范围*/
#define RIGHT 1
int csize=sizeof(char)*2,
tsize=sizeof(TREE2);
TREE2 * t=NULL; /*top, 节点堆栈头指针,*/
/*--------------------------------------------------------*/
main()
{
TREE2 * ht;
if(-1==buildtree(&ht))printf("mk error");
/*preorder(ht); printf("\n\n"); /*test*/
/*midorder(ht); printf("\n\n"); /*test*/
/*posorder(ht); printf("\n"); /*test*/
re_posorder(ht); printf("\n"); /*test*/
re_preorder(ht); printf("\n"); /*test*/
re_midorder(ht); printf("\n"); /*test*/
/*clearmark(ht); /*debug*/
freenode(ht);/***/
getch();
}
/*--------------------------2004.8.07--2004.8.14-----------------------*/
void clearmark(TREE2 * head)
{
TREE2 * t=head;
while(1)
{
t->access=0; t->next=NULL;
/*printf("%c",t->data); /*debug*/
if(t->rlink)push(t->rlink,&top);
if(t->llink)t=t->llink;
else
if(pop(&t,&top))break;
}
}
/*-----------------------2004.9.4--2004.9.5-----------------------------*/
void freenode(TREE2 * head)
{
TREE2 * p;
inQueue(head);
do{
if(outQueue(&p)) {
printf("empty queue");
break;
}
if(p->llink!=NULL) {
inQueue(p->llink); p->llink=NULL;
}
if(p->rlink!=NULL) {
inQueue(p->rlink); p->rlink=NULL;
}
free(p);
}while(front!=NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -