📄 linklist.h
字号:
}
void save_cchsllist_file(link l,string ss)
{
write_llist(l,false,ss);
}
void write_dullist(dulink l,boolean nohead,string ss)
{
dulink p;
boolean k;
int num;
FILE *ff;
if ((ff=fopen(ss,"w"))==NULL){
printf("\nCan't open the file!");
getch();
exit(1);
}
p=l;
k=false;
num=0;
if (!nohead) p=p->next;
while ((p!=NULL) && ((p!=l) || !k)){
num=(num+1) % 10;
if (num==0) fprintf(ff," \n");
fprintf(ff,"%6d",p->data);
p=p->next;
k=true;
}
fprintf(ff,"%6d\n",-9999);
fclose(ff);
}
void save_dllist_file(dulink l,string ss)
{
write_dullist(l,true,ss);
}
void save_hdllist_file(dulink l,string ss)
{
write_dullist(l,false,ss);
}
void save_ccdllist_file(dulink l,string ss)
{
write_dullist(l,true,ss);
}
void save_cchdllist_file(dulink l,string ss)
{
write_dullist(l,false,ss);
}
void save_sllist(link l)
{
save1_sllist(l,0);
}
void save_hsllist(link l)
{
save1_sllist(l,1);
}
void save_ccsllist(link l)
{
save1_sllist(l,2);
}
void save_cchsllist(link l)
{
save1_sllist(l,3);
}
void save_dllist(dulink l)
{
save1_dllist(l,0);
}
void save_hdllist(dulink l)
{
save1_dllist(l,1);
}
void save_ccdllist(dulink l)
{
save1_dllist(l,2);
}
void save_cchdllist(dulink l)
{
save1_dllist(l,3);
}
void sllink_range(link l,int &xl,int &yl,int &xr,int &yr)
{
link p;
if (l!=NULL){
xl=l->x;
yl=l->y;
xr=xl;
yr=yl;
}
else{
xl=0;
yl=0;
xr=0;
yr=0;
}
if (l!=NULL){
p=l->next;
xl=1;
xr=getmaxx()-1;
while ((p!=NULL)&&(p!=l))
{
yl=Min(yl,p->y);
yr=Max(yr,p->y);
p=p->next;
}
yl=yl-5*ndhi;
yr=yr+5*ndhi;
}
}
void clear_sllink_range(link l)
{
int xl,yl,xr,yr;
sllink_range(l, xl,yl,xr,yr);
if (xl+yl+xr+yr!=0)
Clear_range(xl,yl,xr,yr);
}
void dllink_range(dulink l,int &xl,int &yl,int &xr,int &yr)
{
dulink p;
if (l!=NULL){
xl=l->x;
yl=l->y;
xr=xl;
yr=yl;
}
else{
xl=0; yl=0; xr=0; yr=0;
}
if (l!=NULL){
p=l->next;
xl=1;
xr=getmaxx()-1;
while ((p!=NULL)&&(p!=l))
{
yl=Min(yl,p->y);
yr=Max(yr,p->y);
p=p->next;
}
yl=yl-5*ndhi;
yr=yr+5*ndhi;
}
}
void clear_dllink_range(dulink l)
{
int xl,yl,xr,yr;
dllink_range(l, xl,yl,xr,yr);
if (xl+yl+xr+yr!=0) Clear_range(xl,yl,xr,yr);
}
void calnew(int &x,int &y,int key,int dxl,int dyl,int dxr,int dyr)
{
int i,x0,y0;
i=0;
while ((i<=dirnum)&&(key!=mv[i][2])) i=i+1;
x0=x+mv[i][0]*mvstep;
y0=y+mv[i][1]*mvstep;
if ((x0>getmaxx()-dxr)||(x0<dxl)||(y0>getmaxy()-dyr)||(y0<dyl))
printf("\007");
else {
x=x0;
y=y0;
}
}
void mvcur(int &x,int &y,int &dxl,int &dyl,int &dxr,int &dyr,ndfd0 &ff)
{
int key;
boolean funckey;
putimage(x,y,ff,1);
do{
Getkey(key,funckey);
if (!(key>=10&&key<=13))
if ((key==up)||(key==down)||(key==left)||(key==right)||(key==bigleft)||(key==bigright)){
putimage(x,y,ff,1);
calnew(x,y,key,dxl,dyl,dxr,dyr);
putimage(x,y,ff,1);
}
else printf("\007");
}while (!(key>=10&&key<=13));
}
void mmmbtr(int &curx,int &cury)
{
// dir_keyset=[up,down,left,right,bigleft,bigright];
Menu("The Referenced Node is First node");
dxl=sndwd;
dyl=3*ndhi;
dxr=2*sndwd;
dyr=3*ndhi;
mvcur(curx,cury,dxl,dyl,dxr,dyr,snd);
}
void move_sllink_curve(link t,int &curx,int &cury)
{
curx=t->x;
cury=t->y;
mmmbtr(curx,cury);
}
void move_dllink_curve(dulink t,int &curx,int &cury)
{
curx=t->x;
cury=t->y;
mmmbtr(curx,cury);
}
void set_sllist_range(link &l)
{
int curx,cury;
curx=sndwd;
cury=getmaxy() / 6;
// dir_keyset=[up,down,left,right,bigleft,bigright];
Menu("Select the position of the first Node ");
dxl=sndwd;
dyl=3*ndhi;
dxr=2*sndwd;
dyr=3*ndhi;
mvcur(curx,cury,dxl,dyl,dxr,dyr,snd);
comput_snode_card(l,curx,cury);
}
void set_dllist_range(dulink &l)
{
int curx,cury;
curx=sndwd;
cury=getmaxy() / 6;
// dir_keyset=[up,down,left,right,bigleft,bigright];//集合问题没有处理
Menu("Select the position of the first Node ");
dxl=sndwd;
dyl=3*ndhi;
dxr=2*sndwd;
dyr=3*ndhi;
mvcur(curx,cury,dxl,dyl,dxr,dyr,snd);
comput_dnode_card(l,curx,cury);
}
void move_sllist(string s,link &l)
{
int x,y;
move_sllink_curve(l,x,y);
display_llist_from(s,l,true,x,y);
}
void move_hsllist(string s,link &l)
{
int x,y;
move_sllink_curve(l,x,y);
display_llist_from(s,l, false,x,y);
}
void move_ccsllist(string s,link &l)
{
int x,y;
move_sllink_curve(l,x,y);
display_llist_from(s, l, true, x,y);
}
void move_cchsllist(string s,link &l)
{
int x,y;
move_sllink_curve(l,x,y);
display_llist_from(s,l,false,x,y);
}
void move1_sllist(string s,link &l)
{
int x,y;
move_sllink_curve(l, x, y);
clear_sllink_range(l);
display_llist_from(s, l, true, x,y);
}
void move1_hsllist(string s,link &l)
{
int x,y;
move_sllink_curve(l, x, y);
clear_sllink_range(l);
display_llist_from(s, l, false, x,y);
}
void move1_ccsllist(string s,link &l)
{
int x,y;
move_sllink_curve(l, x, y);
clear_sllink_range(l);
display_llist_from(s, l, true, x,y);
}
void move1_cchsllist(string s,link &l)
{
int x,y;
move_sllink_curve(l, x, y);
clear_sllink_range(l);
display_llist_from(s, l, false, x,y);
}
void move_dllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
display_dullist_from(s, l, true, x,y);
}
void move_hdllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l,x,y);
display_dullist_from(s,l,false, x,y);
}
void move_ccdllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
display_dullist_from(s, l, true, x,y);
}
void move_cchdllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
display_dullist_from(s, l, false, x,y);
}
void move1_dllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
clear_dllink_range(l);
display_dullist_from(s, l, true, x,y);
}
void move1_hdllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
clear_dllink_range(l);
display_dullist_from(s, l, false, x,y);
}
void move1_ccdllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
clear_dllink_range(l);
display_dullist_from(s, l, true, x,y);
}
void move1_cchdllist(string s,dulink &l)
{
int x,y;
move_dllink_curve(l, x, y);
clear_dllink_range(l);
display_dullist_from(s, l, false, x,y);
}
void handle_sllist_event(pmenunode &pmenu,link &t)
{
int xl,yl,xr,yr,rrr;
boolean sv;
switch (pmenu->command){
case comcreatelink:
switch (mnlknum) {
case 0: create_single_llist(t);break;
case 1: create_hsingle_llist(t);break;
case 2: create_ccsingle_llist(t);break;
case 3: create_cchsingle_llist(t);break;
}
comput_sllist_card(t,frstcx,frstcy);
break;
case comreadlink: load1_sllist(t,mnlknum);break;
case comsavelink: save1_sllist(t,mnlknum);break;
case comsetrange: set_sllist_range(t);break;
case comdisp: Inputstrinwnd(20,4,60,"Disp LList",ss);
if (mnlknum % 2==1)
disp_sllisthd("sllist",t, true);
else disp_sllisthd("sllist",t,false);
break;
case commove1:
switch (mnlknum){
case 0: move1_sllist("sllist",t);break;
case 1: move1_hsllist("sllist",t);break;
case 2: move1_ccsllist("sllist",t);break;
case 3: move1_cchsllist("sllist",t);break;
}
break;
case commove2:
switch (mnlknum) {
case 0: move_sllist("sllist",t);break;
case 1: move_hsllist("sllist",t);break;
case 2: move_ccsllist("sllist",t);break;
case 3: move_cchsllist("sllist",t);break;
}
break;
}
}
void handle_sllist_menu(mymenu &linkmenu1,boolean &selectorno,pmenunode &pmenu,link &t)
{//linkmenu1 do
Mymenu_selectmenu(linkmenu1,pmenu,selectorno);
if (selectorno)
if (Mymenu_issubmenuitem(linkmenu1)){
Mymenu_disabledispsubmenu(linkmenu1,pmenu->numofmenu / 100);
handle_sllist_event(pmenu,t);
}
else return;
else return;
}
void handle_sllist(link &t)
{
initial_llist();
bmp=Newmenu1(
Newsubmenu1("建链表",
Newmenu1(
Newitem1("建新链表","Input the data to create Linklist ",0,0,comcreatelink,
Newitem1("读文件","Read data From *.Lst File to craete linklist",0,0,comreadlink,
Newitem1("存盘","Save Linklist to *.lst ",0,0,comsavelink,
NULL)))),
Newsubmenu1("显示链表",
Newmenu1(
Newitem1("设定显示区域"," ",0,0,comsetrange,
Newitem1("按原定位置显示","Disp in default mode or old position ",0,0,comdisp,
Newitem1("平移显示 并清除原位","Move the disp to a new position",0,0,commove1,
Newitem1("平移显示 不清除原位","Move to new position, Keep old",0,0,commove2,
NULL))))),
Newsubmenu1("返回",NULL,NULL))));
Mymenu_init(linkmenu1,bmp);
mnlknum=mniscircle*2+mnhavehead;
do {
handle_sllist_menu(linkmenu1,selectorno,pmenu,t);
}while (strcmp(pmenu->menuname,"返回"));
Mymenu_clearmainmenu(linkmenu1);
Mymenu_reset_cursubmenu(linkmenu1);
}
void get_hsllist(link &t)
{
mnhavehead=true;
mniscircle=false;
handle_sllist(t);
}
void get_sllist(link &t)
{
mnhavehead=false;
mniscircle=false;
handle_sllist(t);
}
void get_cchsllist(link &t)
{
mnhavehead=true;
mniscircle=true;
handle_sllist(t);
}
void get_ccsllist(link &t)
{
mnhavehead=false;
mniscircle=true;
handle_sllist(t);
}
void handle_dllist_event(pmenunode &pmenu,dulink &t)
{
int xl,yl,xr,yr,rrr;
boolean sv;
switch (pmenu->command){
case comcreatelink: switch (mnlknum){
case 0: create_dual_llist(t); break;
case 1: create_hdual_llist(t); break;
case 2: create_ccdual_llist(t); break;
case 3: create_cchdual_llist(t); break;
}
comput_dllist_card(t,frstcx,frstcy);
break;
case comreadlink: load1_dllist(t,mnlknum);break;
case comsavelink: save1_dllist(t,mnlknum);break;
case comsetrange: set_dllist_range(t);break;
case comdisp: Inputstrinwnd(20,4,60,"Disp DLList",ss);
disp_dllisthd("dllist",t, mnlknum % 2==1);
break;
case commove1: switch (mnlknum){
case 0: move1_dllist("dllist",t);break;
case 1: move1_hdllist("dllist",t);break;
case 2: move1_ccdllist("dllist",t);break;
case 3: move1_cchdllist("dllist",t);break;
}break;
case commove2: switch (mnlknum){
case 0: move_dllist("dllist",t);break;
case 1: move_hdllist("dllist",t);break;
case 2: move_ccdllist("dllist",t);break;
case 3: move_cchdllist("dllist",t);break;
}break;
}
}
void handle_dllist_menu(mymenu &linkmenu1,boolean &selectorno,pmenunode & pmenu,dulink &t)
{//linkmenu1
Mymenu_selectmenu(linkmenu1,pmenu,selectorno);
if (selectorno){
if (Mymenu_issubmenuitem(linkmenu1)){
Mymenu_disabledispsubmenu(linkmenu1,pmenu->numofmenu / 100);
handle_dllist_event(pmenu,t);
}
else return;
}else return;
}
void handle_dllist(dulink &t)
{
initial_llist();
bmp=Newmenu1(
Newsubmenu1("建链表",
Newmenu1(
Newitem1("建新链表","Input the data to create Linklist ",0,0,comcreatelink,
Newitem1("读文件","Read data From *.Lst File to craete linklist",0,0,comreadlink,
Newitem1("存盘","Save Linklist to *.lst ",0,0,comsavelink,
NULL)))),
Newsubmenu1("显示链表",
Newmenu1(
Newitem1("设定显示区域"," ",0,0,comsetrange,
Newitem1("按原定位置显示","Disp in default mode or old position ",0,0,comdisp,
Newitem1("平移显示 并清除原位","Move the disp to a new position",0,0,commove1,
Newitem1("平移显示 不清除原位","Move to new position, Keep old",0,0,commove2,
NULL))))),
Newsubmenu1("返回",NULL,NULL))));
Mymenu_init(linkmenu1,bmp);
mnlknum=mniscircle*2+mnhavehead;
do{
handle_dllist_menu(linkmenu1,selectorno,pmenu,t);
}while (strcmp(pmenu->menuname,"返回"));
Mymenu_clearmainmenu(linkmenu1);
Mymenu_reset_cursubmenu(linkmenu1);
}
void get_hdllist(dulink &t)
{
mnhavehead=true;
mniscircle=false;
handle_dllist(t);
}
void get_dllist(dulink &t)
{
mnhavehead=false;
mniscircle=false;
handle_dllist(t);
}
void get_cchdllist(dulink &t)
{
mnhavehead=true;
mniscircle=true;
handle_dllist(t);
}
void get_ccdllist(dulink &t)
{
mnhavehead=false;
mniscircle=true;
handle_dllist(t);
}
void freelink(link pl)
{
link ptmp1 = NULL;
link ptmp = pl;
while(pl != NULL){
while(pl->next != NULL){
ptmp1 = pl;
pl = pl->next;
}
if(pl == ptmp){
free(pl);
ptmp = NULL;
}else{
free(pl);
ptmp1->next = NULL;
}
pl = ptmp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -