📄 btrechar.h
字号:
#include "tools.h"
#include "toolchar.h"
const char * extendname="cbt";
struct bnode{
int ltag,rtag;//-1..1
struct bnode *lchild,*rchild;
datatype data;
int w,lw,rw,x,y;
};
typedef struct bnode *bitre;
typedef int ldr;//-1..3
struct grbinode{
struct grbinode *father,*lchild,*rchild;
datatype data;
boolean hvdt;
int x,y;
int lr; //-1..3
};
typedef struct grbinode *grbitre;
typedef void far * ndfd;
struct bnodeptr{
string ptrname;
bitre ptr;
struct bnodeptr *next;
int x,y,num;
ndfd fd0;
};
typedef struct bnodeptr * bptrlink;
bptrlink frstbptr=NULL;
int bnum=0;
int bitre_graph_state=0;
int bitrecount=0;
void create_bptr(bptrlink &sptr,string title);
void bptr_point_to(bptrlink &sptr,bitre sp);
void disp_bptr_atbnode(bptrlink &sptr,bitre sp);
boolean have_bptr(string title);
void create_ex_bitre(bitre &t);
void create_gr_bitre(bitre &t);
void inorder( bitre t);
void preorder(bitre t);
void postorder(bitre t);
int high(bitre t);
int width(bitre t);
void copy_bitre(bitre t,bitre &tt);
void dispose_bitre(bitre &tt);
void display_bitre(string s,bitre &t);
void display_threaded_bitre(string s,bitre &tt);
void copy_threaded_bitre(bitre tt,bitre &ttp);
void copy_thread_bitre(bitre tt,bitre &ttp);
void pre_thread_bitre(bitre t,bitre &tt);
void in_thread_bitre(bitre t,bitre &tt);
void post_thread_bitre(bitre t,bitre &tt);
void save_bitre_file(bitre t,string ss);
void save_bitre(bitre t);
void load_bitre_file(bitre &t,string ss);
void load_bitre(bitre &t);
void initial_bitre();
void clear_bitre_range(bitre t);
void dis_bitre(bitre tt);
void dis_thbitre(bitre tt);
void disp_bitre(string s,bitre &tt);
void comput_bitre_card(bitre &tt);
void disp_thbitre(string s,bitre &tt);
void comput_thbitre_card(bitre &tt);
void cur_bnode_onoff(bitre t);
void disp_bnode_data(bitre t);
void put_bnode_data(bitre &t,datatype x);
void bitre_range(bitre t,int &xl,int &yl,int &xr,int &yr);
void change_card_to(bitre &t, int x,int y);
void change_card_dxy(bitre &t,int dx,int dy);
void set_bitre_range(bitre &t);
void set_thbitre_range(bitre &t);
void move_bitre_dxy(string s,bitre &t,int dx,int dy);
void move_bitre_to(string s,bitre &t, int x1,int y1);
void move_bitre(string s, bitre &t);
void move_thbitre_dxy(string s,bitre &t,int dx,int dy);
void move_thbitre_to(string s,bitre &t, int x1,int y1);
void move_thbitre(string s, bitre &t);
void move1_bitre(string s, bitre &t);
void move1_thbitre(string s, bitre &t);
void disp_bitre_at(string s,bitre &tt,int x,int y);
void disp_thbitre_at(string s,bitre &tt,int x,int y);
void write_atbnode_angle(bitre t,int an,string ss);
void writestr_atbnode_angle(bitre t,int an,string ss);
void writeint_atbnode_angle(bitre t,int an,int ii);
void dispstr_atbnode_angle(string ss, bitre t,int an);
void dispint_atbnode_angle(int ii,bitre t,int an);
void lthread_point_to(bitre t1,bitre t2);
void rthread_point_to(bitre t1,bitre t2);
void reset_tag(bitre &t);
void handle_bitre_event(pmenunode &pmenu,bitre &t);
void handle_bitre_menu(mymenu &bitremenu1,boolean &selectorno,pmenunode &pmenu,bitre &t);
void handle_bitre(bitre &t);
void get_bitre(bitre &t);
void set_vbnode_mode();
void visite_bnode(bitre &t, int i);
void reset_vbnode_mode(int i);
int k,xm,ym,i;
//boolean funckey;
char j;
ndfd fd1,fd2,fd3,fd4,bnfd;
const int ld=6;
const int dd=40;
const int rd=ld;
int hd=10;
const int keystep=8;
const int bigstep=40;
const int sd=4;
const int lt=-1;
const int d=0;
const int r=1;
const int m=2;
int steprow=20;
int startrow=30;
int radiux=8;
int radiuy=8;
int radius4=32;
int strt_row=20;
int strt_col=20;
int step_row=44;
int step_col=24;
int hi,mx,my,xl,yl,xr,yr,dxl,dyl,dxr,dyr;
typedef void far *ffield;
ffield nd1,ff,chldfild,datafild,ff1,ndcur,newroot;
int w,lsz,may,key;
grbitre grbt;
string ss;
unsigned int dir_keyset;//1..255
word size;
const int mvkeystep=5;
const int dirnum=6;
int mvstep=5;
typedef int move[dirnum][3];
move mv={{0,-1, up},{0,1,down},{-1,0,left},{1,0,right},{-4,0,bigleft},{4,0,bigright}};
const int comgrcreatebitre=201;
const int comexcreatebitre=202;
const int comreadbitre=203;
const int comsavebitre=204;
const int comsetrange=205;
const int comdisp=206;
const int commove1=207;
const int commove2=208;
mymenu bitremenu1;
pmenunode bmp;
string yn1;
char yn,ch,ccc;
const int comwritedata=801;
const int comnotwritedata=802;
const int comusecurmove=803;
const int comusecurkeep=804;
const int comnotusecur=805;
const int comwaitkey=806;
const int comdelay=807;
const int comnotpause=808;
const int comuseptr=809;
const int comnotuseptr=810;
const int comneedno=811;
const int comnotneedno=812;
const int comselectmodeno=813;
const int numofvstmode=4;
struct visitemode{
boolean ifwrite,ifcurcovermove,ifcurcoverkeep,ifwaitkey,ifdelay,ifuseptr,ifusenum,ifdispnum;
int delaytime,num,numangle;
bptrlink ptr;
string ptrname;
};
typedef struct visitemode vstmdarr[numofvstmode];
mymenu vstmenu1,vstmenu2;
pmenunode vstmp1,vstmp2;
int vstno=1;
struct visitemode onevisitemode={true,true,false,true,false,true,/*false};*/true,true,
0,0,270,
NULL,"t"};
vstmdarr visitebtmodes;
void initial_visitemode(vstmdarr &visitemodes)
{
int i;
char stemp[255];
for(i=0;i<numofvstmode;i++){
Convs(i,stemp);
strcpy(visitemodes[i].ptrname,"t");
strcat(visitemodes[i].ptrname,stemp);
if ( visitemodes[i].ifuseptr && ! have_bptr(visitemodes[i].ptrname))
create_bptr(visitemodes[i].ptr,visitemodes[i].ptrname);
bptr_point_to(visitemodes[i].ptr,NULL);
if ( visitemodes[i].ifusenum ) visitemodes[i].num=0;
}
}
void reset_vbnode_mode( int i)
{
// with visitebtmodes[i] do
if ( visitebtmodes[i-1].ifuseptr) bptr_point_to(visitebtmodes[i-1].ptr,NULL);
visitebtmodes[i-1].num=0;
}
void visite_bnode(bitre &t,int i)
{
char ss[255],s1[255],stemp[255];
Convs(i,stemp);
strcpy(ss,"访问模式 ");
strcat(ss,stemp);
strcat(ss," 访问元素方式: ");
strcpy(s1,"");
if (t!=NULL){
if (visitebtmodes[i-1].ifwrite) strcpy(s1," 打印元素");
if (visitebtmodes[i-1].ifcurcovermove ||visitebtmodes[i-1].ifcurcoverkeep ) strcat(s1," 显示光标");
if (visitebtmodes[i-1].ifuseptr) strcat(s1," 用指示器");
if (visitebtmodes[i-1].ifusenum) strcat(s1," 显示序号");
if (visitebtmodes[i-1].ifwaitkey) strcat(s1," 按键继续");
else
if (visitebtmodes[i-1].ifdelay ){
Convs(visitebtmodes[i-1].delaytime,stemp);
strcat(s1," delay ");
strcat(s1,stemp);
strcat(s1," ms to cont.");
}
strcat(ss," by");
strcat(ss,s1);
Menu(ss);
if ( visitebtmodes[i-1].ifwrite ) printf("%c ",t->data);
if ( visitebtmodes[i-1].ifcurcovermove || visitebtmodes[i-1].ifcurcoverkeep) cur_bnode_onoff(t);
if ( visitebtmodes[i-1].ifuseptr ) bptr_point_to(visitebtmodes[i-1].ptr,t);
if ( visitebtmodes[i-1].ifusenum ) visitebtmodes[i-1].num=visitebtmodes[i-1].num+1;
if ( visitebtmodes[i-1].ifusenum && visitebtmodes[i-1].ifdispnum ) dispint_atbnode_angle(visitebtmodes[i-1].num, t,visitebtmodes[i-1].numangle);
if ( visitebtmodes[i-1].ifwaitkey ) getch();
else
if ( visitebtmodes[i-1].ifdelay ) delay(visitebtmodes[i-1].delaytime);
if ( visitebtmodes[i-1].ifcurcovermove) cur_bnode_onoff(t);
}
}
void rangeerror()
{
printf("\007");
Error("数据范围错!");
}
void handle_visite2_event(pmenunode &pmenu,vstmdarr &visitemodes)
{
int xl,yl,xr,yr,state;
boolean sv;
char stemp[255],sstemp[255];
if ((pmenu->command>=800) && (pmenu->command<=815)){
switch (pmenu->command){
case comselectmodeno:
do{
strcpy(stemp,"选择采用的访问方式号[1..");
Convs(numofvstmode,sstemp);
strcat(stemp,sstemp);
strcat(stemp,"] ");
Editintinwnd(20,4,60,stemp,vstno);
if ((vstno<1)||(vstno>4)) rangeerror();
}while ((vstno<1)||(vstno>4));
break;
case comwritedata:
do{
state=2-visitemodes[vstno-1].ifwrite;
Editintinwnd(20,4,60,"1--打印元素值 2--不打印元素值",state);
if ( (state!=1)&&(state!=2)) rangeerror();
else
if (state==1) visitemodes[vstno-1].ifwrite=true;
else visitemodes[vstno-1].ifwrite=false;
}while ( (state!=1)&&(state!=2));
break;
case comusecurmove:
do{
state=3-(2*(visitemodes[vstno-1].ifcurcovermove)+(visitemodes[vstno-1].ifcurcoverkeep));
Editintinwnd(10,4,70,"1--覆盖光棒然后移去 2--使用光棒不移去 3--不使用光棒",state);
if ((state!=1)&&(state!=2)&&(state!=3)) rangeerror();
else{
if (state==1) visitemodes[vstno-1].ifcurcovermove=true;
else visitemodes[vstno-1].ifcurcovermove=false;
if (state==2) visitemodes[vstno-1].ifcurcoverkeep=true;
else visitemodes[vstno-1].ifcurcoverkeep=false;
}
}while ((state!=1)&&(state!=2)&&(state!=3));
break;
case comwaitkey:
do{
state=3-(2*(visitemodes[vstno-1].ifwaitkey)+(visitemodes[vstno-1].ifdelay));
Editintinwnd(10,4,70,"1--等待按键继续 2--自动延迟时间 3--访问后不停顿",state);
if ((state!=1)&&(state!=2)&&(state!=3)) rangeerror();
else{
if (state==1) visitemodes[vstno-1].ifwaitkey=true;
else visitemodes[vstno-1].ifwaitkey=false;
if (state==2) visitemodes[vstno-1].ifdelay=true;
else visitemodes[vstno-1].ifdelay=false;
if ( state==2 )
do{
Editintinwnd(20,6,60,"延迟时间[0..10000]毫秒: ",visitemodes[vstno-1].delaytime);
if ( (visitemodes[vstno-1].delaytime<0) || (visitemodes[vstno-1].delaytime>10000)) rangeerror();
}while ((visitemodes[vstno-1].delaytime<0) || (visitemodes[vstno-1].delaytime>10000));
}
}while ((state!=1)&&(state!=2)&&(state!=3));
break;
case comuseptr:
do{
state=2-(visitemodes[vstno-1].ifuseptr);
visitemodes[vstno-1].ifuseptr=false;
Editintinwnd(20,4,60,"1--使用指示器 2--不使用指示器",state);
if ( state==1 )
do{
Convs(vstno,sstemp);
strcpy(visitemodes[vstno-1].ptrname,"t");
strcat(visitemodes[vstno-1].ptrname,sstemp);
Editstrinwnd(20,6,60,"所使用的指示器名称为:",visitemodes[vstno-1].ptrname);
if ( have_bptr(visitemodes[vstno-1].ptrname)) rangeerror();
else visitemodes[vstno-1].ifuseptr=true;
}while (have_bptr(visitemodes[vstno-1].ptrname));
else visitemodes[vstno-1].ifuseptr=false;
}while ((state!=1)&&(state!=2));
break;
case comneedno:
do{
state=2-(visitemodes[vstno-1].ifusenum);
Editintinwnd(20,4,60,"1--显示序号 2--不显示序号 ",state);
if ( state==1 )
do{
Editintinwnd(20,6,60,"显示序号的角度[0..360]:",visitemodes[vstno-1].numangle);
if ((visitemodes[vstno-1].numangle<0) || (visitemodes[vstno-1].numangle>360)) rangeerror();
}while ((visitemodes[vstno-1].numangle<0) || (visitemodes[vstno-1].numangle>360));
if (state==1) visitemodes[vstno-1].ifusenum=true;
else visitemodes[vstno-1].ifusenum=false;
}while ((state!=1)&&(state!=2));
break;
}
}
}
void handle_visite2_menu(mymenu &vstmenu2,boolean &selectorno,pmenunode &pmenu,vstmdarr &visitemodes)
{
// with vstmenu2 do
Mymenu_selectmenu(vstmenu2,pmenu,selectorno);
if ( selectorno)
if (Mymenu_issubmenuitem(vstmenu2)){
Mymenu_disabledispsubmenu(vstmenu2,pmenu->numofmenu / 100);
handle_visite2_event(pmenu,visitemodes);
}else return;
else return;
}
void handle_visite2_mode(vstmdarr &visitemodes)
{
bitre_graph_state=0;
initial_bitre();
vstmp2=Newmenu1(
Newsubmenu1("置访问方式",
Newmenu1(
Newitem1("选择访问方式号","选择访问方式号... ",0,0,comselectmodeno,
Newitem1("设置打印元素值","设置是否打印元素的值... ",0,0,comwritedata,
Newitem1("使用光棒方式","设置是否使用光标... ",0,0,comusecurmove,
Newitem1("设置停顿方式","设置在两次访问之间是否需要停顿... ",0,0,comwaitkey,
Newitem1("设置使用指示器","设置是否需要指示器指示结点.. ",0,0,comuseptr,
Newitem1("显示序号","设置是否需要显示序号...",0,0,comneedno,
NULL))))))),
Newsubmenu1("返回",NULL,NULL)));
Mymenu_init(vstmenu2,vstmp2);
do
handle_visite2_menu(vstmenu2,selectorno,pmenu,visitemodes);
while (strcmp(pmenu->menuname,"返回"));
Mymenu_clearmainmenu(vstmenu2);
initial_visitemode(visitebtmodes);
}
void set_vbnode_mode()
{
handle_visite2_mode(visitebtmodes);
}
void disp_bnode_data(bitre t)
{
getimage(t->x-radiux,t->y-radiuy,t->x+radiux,t->y+radiuy,nd1);
putimage(t->x-radiux,t->y-radiuy,nd1,1);
ellipse(t->x,t->y,0,360,radiux,radiuy);
outtextxy(t->x,t->y,conv(t->data));
}
void put_bnode_data(bitre &t,datatype x)
{
t->data=x;
disp_bnode_data(t);
}
void cur_bnode_onoff(bitre t)
{
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(forecolor);
directvideo=false;
w=ld+rd+dd;
setfillpattern(fillmode,fillcolor);
size=imagesize(1,1,20,20);
ndcur=farmalloc(size);
bar(1,1,20,20);
getimage(1,1,20,20,ndcur);
putimage(1,1,ndcur,1);
putimage(t->x-10,t->y-10,ndcur,1);
}
boolean have_bptr(string title)
{
bptrlink p;
if ( bnum==0 ) frstbptr=NULL;
p=frstbptr;
while ( (p!=NULL) && (p->ptrname!=title)) p=p->next;
if (p!=NULL) return true;
else return false;
}
void create_bptr(bptrlink &sptr,string title)
{
bptrlink p;
int l;
if (bnum==0) frstbptr=NULL;
p=frstbptr;
while (p!=NULL)
if (strcmp(p->ptrname,title)) p=p->next;
else Error("the pointer have exist!");//_exit}
sptr=(bptrlink)malloc(sizeof(struct bnodeptr));
bnum=bnum+1;
sptr->next=frstbptr;
frstbptr=sptr;
strcpy(sptr->ptrname,title);
sptr->x=-1;
sptr->y=-1;
sptr->ptr=NULL;
l=8*strlen(sptr->ptrname) / 2;
// getimage(1,1,2*l,9,fd0);
// putimage(1,1,fd0,1);
outtextxy(l,5,sptr->ptrname);
size=imagesize(1,1,2*l,9);
sptr->fd0=farmalloc(size);
getimage(1,1,2*l,9,sptr->fd0);
putimage(1,1,sptr->fd0,1);
}
void ptrcases(bptrlink &sptr,int l)
{
putimage(sptr->x,sptr->y,sptr->fd0,1);
switch (sptr->num){
case 1: putimage(sptr->x+l,sptr->y+8, fd1,1);break;
case 2: putimage(sptr->x+l,sptr->y-20,fd2,1);break;
case 3: putimage(sptr->x+2*l,sptr->y+4, fd3,1);break;
case 4: putimage(sptr->x-20, sptr->y+4, fd4,1);break;
}
}
void bptr_point_to(bptrlink &sptr,bitre sp)
{
bptrlink p;
int k,n,l,sg;
n=0;
l=8*strlen(sptr->ptrname) / 2;
k=0;
if (sp!=NULL){
p=frstbptr;
while ((p!=NULL)){
if ((p->ptr==sp) && (strcmp(p->ptrname,sptr->ptrname))) n=n+1;
p=p->next;
k=k+1;
}
// if (sptr->x>0) ptrcases(sptr,l);
sptr->ptr=sp;
sptr->num=n % 4+1;
switch (sptr->num){
case 1:{sptr->x=sp->x-l;sptr->y=sp->y-36;break;}
case 2:{sptr->x=sp->x-l;sptr->y=sp->y+28;break;}
case 3:{sptr->x=sp->x-2*l-28;sptr->y=sp->y-4;break;}
case 4:{sptr->x=sp->x+28;sptr->y=sp->y-4;break;}
}
ptrcases(sptr,l);
}else{
sptr->x=0;
sptr->y=0;
sptr->ptr=NULL;
}
}
void disp_bptr_atbnode(bptrlink &sptr,bitre sp)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -