?? family.cpp
字號:
#include"jiapu.h"
#include"frame.h"
#include "else.h"
#include <stdlib.h>
#include <fstream>
bitree create(HANDLE hOut ,HANDLE hIn) //初始化 創建文件
{
bitree t;
t=new bitnode;
COORD pos={22,12};
SetConsoleCursorPosition(hOut,pos);
cout<<"輸入家譜名:";
cin>>t->a.parentname ;
char name[24];
strcpy(name,t->a.parentname);
strcat(name,".dll");
if(FileExist(name))
{
if(frame4(hOut,hIn));
else
{
t=NULL;
return t;
}
}
strcat(t->a.parentname,".dll");
strcpy(t->a.birthaddress,"###");
strcpy(t->a.birthday,"###");
strcpy(t->a.consort,"###");
strcpy(t->a.zhiche,"###");
strcpy(t->a.deathday,"###");
strcpy(t->a.name,"###");
strcpy(t->a.sex,"###");
strcpy(t->a.stature,"###");
strcpy(t->a.work,"###");
strcpy(t->a.xueli,"###");
pos.Y+=2;
SetConsoleCursorPosition(hOut,pos);
cout<<" 輸入族長的信息"<<endl;
t=cinnode(t,hOut);
if(t){
t->lchild =NULL;
t->parent =NULL;
t->rchild =NULL;
}
return t;
}
bitnode* search(bitree &T,char name[30]) //查找 返回節點
{
bitnode*p,*q;
if(T)
{
if(!strcmp(T->a.name,name))
return T;
p=search(T->lchild ,name);
q=search(T->rchild ,name);
if(p)return p;
else return q;
}
return T;
}
bitree insert(bitree&T) //添加新成員
{
HANDLE hOut,hIn;
INPUT_RECORD mouseRec;
DWORD res;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 獲取標準輸出設備句柄
hIn = GetStdHandle(STD_INPUT_HANDLE); // 獲取標準輸入設備句柄
if(!T)
{
T=create(hOut,hIn);
return T;
}
else
{
COORD pos={21,13};
SetConsoleCursorPosition(hOut,pos);
cout<<" 雙擊擊添加人的父親或輸入父親的姓名";
COORD pos1={28,14};
button a,*pp,h;
COORD posh2={47,9};
h.createbutton(posh2," ↖ ",14,236,hOut);
a.createbutton(pos1,"輸入父親姓名",14,236,hOut);
char name[30];
int x=countnode(T);
pp=print1(T,pp,x,hOut);
for(;;)
{
BOOL tal=false;
ReadConsoleInput(hIn, &mouseRec, 1,&res);
mousemove1(hOut,hIn,a,mouseRec);
for(int k=0;k<x;k++)
{
if(!pp[k].p)
pp[k].hidebutton(hOut,true);
mousemove1(hOut,hIn,pp[k],mouseRec);
}
mousemove(hOut,hIn,h,mouseRec);
// mousemove(hOut,hIn,g,mouseRec);
if(mouseclickl(hOut,hIn,h,mouseRec))
return T;
if(mouseclickl(hOut,hIn,a,mouseRec))
{
pos1.X+=12;
SetConsoleCursorPosition(hOut,pos1);
cin>>name ;
break;
}
else
{
for(int j=0;j<x;j++)
{
if(mousedoubleclick(hOut,hIn,pp[j],mouseRec))
{
strcpy(name,pp[j].buttonname);
tal=true;
break;
}
}
//break;
}
if(tal)
break;
}
COORD posq1={21,13},posq2={180,180};//用于清屏
clearscreen(hOut,posq1,posq2);
bitnode*q;
q=search(T,name); //查找q
if(!q) //沒有找到name
{
if(frame2(hOut,hIn,"此人不存在!"));//cout<<"輸入有誤!!"<<endl;
return T;
}
else
{
bitnode *p;
p=new bitnode;
strcpy(p->a.parentname,name);
strcpy(p->a.birthaddress,"###");
strcpy(p->a.birthday,"###");
strcpy(p->a.consort,"###");
strcpy(p->a.zhiche,"###");
strcpy(p->a.deathday,"###");
strcpy(p->a.name,"###");
strcpy(p->a.sex,"###");
strcpy(p->a.stature,"###");
strcpy(p->a.work,"###");
strcpy(p->a.xueli,"###");
p=cinnode(p,hOut);
/*cout<<"姓名:";
cin>>p->a.name ;
*/
if(!p)return T;
p->lchild =NULL;
p->parent =NULL;
p->rchild =NULL;
// p->a.namel=p->a.name .length ();
if(!q->lchild) //情況1
{
p->parent =q;
// p->a.parentname =q->a.name ;
q->lchild =p;
p->lchild =NULL;
p->rchild =NULL;
// T->nodenum++;
}
else //情況2
{
// p->a.parentname =q->a.name ;
q=q->lchild ;
while(q->rchild )
q=q->rchild ;
q->rchild =p;
p->parent =q;
p->lchild =NULL;
p->rchild =NULL;
// T->nodenum++;
}
p=NULL;
delete p;
return T;
}
}
}
bitree insert1(bitree&T,bitnode*p)
{
bitnode*q;
q=search(T,p->a.parentname); //查找q
// cout<<q->a.name ;
if(!q->lchild) //情況1
{
p->parent =q;
q->lchild =p;
p->lchild =NULL;
p->rchild =NULL;
}
else //情況2
{
q=q->lchild ;
while(q->rchild )
q=q->rchild ;
q->rchild =p;
p->parent =q;
p->lchild =NULL;
p->rchild =NULL;
}
p=NULL;
return T;
}
void print(bitree t) //打印家譜┣ ━ ┳ ┃┣ ┗
{
HANDLE hOut,hIn;
hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 獲取標準輸出設備句柄
hIn = GetStdHandle(STD_INPUT_HANDLE); // 獲取標準輸入設備句柄
if(!t)
if(!frame2(hOut,hIn,"家譜為空!!"))
return;
else
{
int l,y,x;
COORD pos= {22,16}; //輸出位置
SetConsoleCursorPosition(hOut,pos); //設置光標的位置
cout<<"┣";
pos.X+=2;
SetConsoleCursorPosition(hOut,pos); //設置光標的位置
bitnode *s,*stack[200];
int top=0;
stack[top]=t;
while(top>=0)
{
s=stack[top--]; //出棧
if(!s->parent)
{;}
else
{
y=pos.Y +2;
pos=s->pos;
for(;pos.Y <y;pos.Y ++)
{
SetConsoleCursorPosition(hOut,pos);//重新設置光標的位置
cout<<"┃";
}
SetConsoleCursorPosition(hOut,pos);//重新設置光標的位置
if(s->rchild)
{
cout<<"┣";
}
else
{
cout<<"┗";
}
pos.X =pos.X +2;
SetConsoleCursorPosition(hOut,pos);//重新設置光標的位置
}
while(s)
{
cout<<s->a.name ;
l=strlen(s->a.name) ;
x=pos.X;
if(s->lchild)
{
cout<<"━";
if(s->lchild ->rchild )
{
cout<<"┳";
}
else
{
cout<<"━";
}
pos.X =pos.X+4+l;
SetConsoleCursorPosition(hOut,pos);//重新設置光標的位置
}
if(s->rchild)
{
stack[++top]=s->rchild ;//入棧
stack[top]->pos .X =x-2; //記錄光標的位置
stack[top]->pos.Y=pos.Y +1;
}
s=s->lchild ;
}
}
cout<<endl<<endl;}
}
void destroy(bitnode*p)
{
if(p)
{
destroy(p->lchild );
destroy(p->rchild );
delete p;
// t->nodenum--;
}
}
bitree del(bitree&t) //刪除節點
{
HANDLE hOut,hIn;
INPUT_RECORD mouseRec;
DWORD res;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 獲取標準輸出設備句柄
hIn = GetStdHandle(STD_INPUT_HANDLE); // 獲取標準輸入設備句柄
bitnode *p;
char name[30];
p=new bitnode;
// string name;
button a,*pp,h;
COORD posh2={47,9};
h.createbutton(posh2," ↖ ",14,236,hOut);
COORD pos1={28,14};
a.createbutton(pos1,"輸入姓名",14,236,hOut);
int x=countnode(t);
pp=print1(t,pp,x,hOut);
COORD pos={21,13};
SetConsoleCursorPosition(hOut,pos);
cout<<" 雙擊要刪除的人或輸入他的姓名:";
for(;;)
{
BOOL tal=false;
ReadConsoleInput(hIn, &mouseRec, 1,&res);
mousemove1(hOut,hIn,a,mouseRec);
for(int k=0;k<x;k++)
{
if(!pp[k].p)
pp[k].hidebutton(hOut,true);
mousemove1(hOut,hIn,pp[k],mouseRec);
}
mousemove(hOut,hIn,h,mouseRec);
if(mouseclickl(hOut,hIn,h,mouseRec))
return t;
if(mouseclickl(hOut,hIn,a,mouseRec))
{
pos1.X+=8;
SetConsoleCursorPosition(hOut,pos1);
cin>>name ;
break;
}
else
{
for(int j=0;j<x;j++)
{
if(mousedoubleclick(hOut,hIn,pp[j],mouseRec))
{
strcpy(name,pp[j].buttonname);
tal=true;
break;
}
}
//break;
}
if(tal)
break;
}
// bitnode*q=new bitnode;
p=search(t,name); //查找q
if(!p) //沒有找到name
{
//pos.Y=pos.Y+1;
// SetConsoleCursorPosition(hOut,pos);
//cout<<" 無此人!!";
if(frame2(hOut,hIn,"此人不存在!"));
return t;
}
/* else
{
if(!p->parent)
{
destroy(p,t);
t=NULL;
}*/
else
{
if(!p->lchild&&!p->rchild ) //該節點為葉子節點
{
if(!p->parent )
{
// t->nodenum--;
t=NULL;
//delete p;
}
else
{
if(p->parent ->lchild &&p->parent ->lchild ==p)
{
p->parent ->lchild =NULL;
p->parent =NULL;
// t->nodenum--;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -