📄 operate.c
字号:
/*
******************************************************************************************
*
* 功 能 :操作菜单
* 作 者 :林永表
* 日 期 :2009-4-5
*
******************************************************************************************
*/
/*
*功 能:函数声明
*/
#include <stdio.h>
#include <stdlib.h>
#include "define.h"
void creat_thread_btree(ptr_thread_btree*);
void iner_thread_btree(ptr_thread_btree);
void iner_thread(ptr_thread_btree,ptr_thread_btree *);
void display_ransack()
{
printf("\t\t\t*****************************\t\tauthor:lybrysh\n");
printf("\t\t\t\t遍历线索二叉树\n");
printf("\n\t\t\t\ta.前序线索遍历\n\t\t\t\tb.中序线索遍历\n\t\t\t\tc.后序线索遍历\n");
printf("\t\t\t\td.重新建二叉树\n");
printf("\t\t\t*****************************\n");
}
void operatefun()
{
char ch=0,flag='y';
INTEGER def=1;
ptr_thread_btree *h_btree; //指向线索树的地址的指针。
ptr_thread_btree *pre; //指针的指针,要不然在递归调用中传回来的地址值并没有改变
pre=(ptr_thread_btree *)malloc(N*sizeof(ptr_thread_btree *));
if(!pre)
{
printf("\n内存分配失败!\n");
exit(1);
}
*pre=(ptr_thread_btree )malloc(N*sizeof(ptr_thread_btree ));
if(!(*pre))
{
printf("\n内存分配失败!\n");
exit(1);
}
h_btree=(ptr_thread_btree *)malloc(N*sizeof(ptr_thread_btree *));
if(!h_btree)
{
printf("\n内存分配失败!\n");
exit(1);
}
*h_btree=(ptr_thread_btree)malloc(N*sizeof(ptr_thread_btree));
if(!(*h_btree))
{
printf("\n内存分配失败!\n");
exit(1);
}
display_ransack();
creat_thread_btree(h_btree);
do
{
getchar();
system("cls");
display_ransack();
printf("\n请输入你的选择:"); //输入主菜单中的操作选择
ch=getchar();
switch(ch)
{
case 'a':
printf("\n对不起,暂时没有这种遍历的实现~^~\n\n");
break;
case 'b':
if(def)
iner_thread(*h_btree,pre); //防止用户再次使用该方法遍历时又重新线索化
//这里一次线索化即可多次使用,但注意其他方法
//线索化时应对应其他的遍历方法
printf("\n遍历中序线索化的二叉树为: ");
iner_thread_btree(*h_btree);
def=0;
break;
case 'c':
printf("\n对不起,暂时没有这种遍历的实现~^~\n\n");
break;
case 'd':
system("cls");
operatefun();
break;
default :
break;
}
getchar();
printf("请按任意键继续!");
getchar();
system("cls");
display_ransack();
printf("\n你还要继续吗?(y/n)\n");
flag=getchar();
}while('y'==flag||'Y'==flag);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -