⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linklist.h

📁 该包是数据结构的实验软件,来源于合肥工业大学人工智能与数据挖掘实验室,用来实现数据结构.
💻 H
📖 第 1 页 / 共 4 页
字号:
{
	disp_dllisthd(s,l,true);
}

void  disp_dllist(string s,dulink l)
{
	disp_dllisthd(s,l,false);
}

void  disp_cchdllist(string s,dulink l)
{
	disp_dllisthd(s,l,true);
}

void  disp_ccdllist(string s,dulink l)
{
	disp_dllisthd(s,l,false);
}


void print_dullist(dulink l,boolean nohead)
{
	dulink p;
	boolean k;
	p=l;
	k=false;
	if (!nohead) p=p->next;
    while ((p!=NULL)&&((p!=l)||!k)){
		printf("%6d",p->data);
		p=p->next;
		k=true;
		} 
	printf("\n");
	getch();
}


void print_dulllist(dullink l,boolean nohead)
{
	dullink p;
	boolean k;
	p=l;
	k=false;
	if (!nohead) p=p->next;
	while ((p!=NULL)&&((p!=l)||!k)){
		printf("%6d",p->data);
		p=p->next;
		k=true;
		}
	printf("\n");
	getch();
}

void createdulink(dulink &pre,dulink &t)
{
	datatype ch;
	scanf("%d",&ch);
	if (ch==num_of_end)  t=NULL;
	else{
		t=(dulink)malloc(sizeof(struct dunode));
		t->prior=pre;
        t->data=ch; 
        createdulink(t,t->next);
		}
}

void  create_hdual_llist(dulink &l)
{
    dulink p;
    Into_graph();
    printf("\n");
    window(1,3,80,25);
    textbackground(BLACK);
    textcolor(WHITE);
    printf("%45s%d\n","The end num is ",num_of_end);
    printf("%68s\n","Please input the value of the Linklist elements in order");
    l=(dulink)malloc(sizeof(struct dunode));
    l->prior=NULL;
    createdulink(l,l->next);
    l->data=0;
    Wait();
    printf("   OK");
    gotoxy(1,1);
    comput_dllist_card(l,frstcx,frstcy);
}

void dispose_dullist(dulink &l)
{
    dulink p,tp;
    p=l;
    tp=l->next;
    while ((tp!=NULL)&&(tp!=l)){
	free(p);
	p=tp;
	tp=tp->next;
	}
}

void comput_dnode_card(dullink &tt,int frstcx,int frstcy)
{
    dullink p;
    int cx,cy,mx,my;
    p=tt;
    cx=frstcx;
    cy=frstcy;
    mx=getmaxx();
    do{
	p->x=cx;
		p->y=cy;
		p->hvds=false;
		if (cx+2*dndwd+arrlen+20>mx){
			cx=30;
			cy=cy+3*ndhi;
		}else  cx=cx+dndwd+arrlen;
		p=p->next;
	}while (!((p==NULL)||(p==tt)));
	getch();
}

void comput_dllist_card(dullink &tt,int frstcx,int frstcy)
{
	comput_dnode_card(tt,frstcx,frstcy);
}


void dis_llist2(dullink tp,dulink tt,int x1,int y1,boolean nohead,boolean is_first)
{
	char stemp[255];
	if (tt==NULL) drawnil(x1,y1);
	else{
		if ((tt->prior==NULL)&&is_first)
		drawnil(tt->x+3,tt->y+ndhi / 2);
	    if ((tt==tp)&&!is_first){
	    	Arrowdot(x1,y1,x1+10,y1);
            line(x1+10,y1,x1+10,y1+ndhi*2);
		    line(x1+10,y1+ndhi*2,5,y1+2*ndhi);
		    line(5,y1+2*ndhi,5,tt->y+3);
            Arrow(5,tt->y+3,tt->x,tt->y+3);
            if (tt->prior==NULL) drawnil(tt->x+3,tt->y+ndhi / 2);
		    else{
		    	Arrowdot(x1+8,y1+3,x1+3,y1+3);
                line(x1+8,y1+3,x1+8,y1+ndhi*2-3);
                line(x1+8,y1+ndhi*2-3,8,y1+2*ndhi-3);
			   	line(8,y1+2*ndhi-3,8,tt->y+9);
                Arrow(tt->x+3,tt->y+6,8,tt->y+6);
            	}
           }
	    else{
	    	if ((tt->x>x1)&&(abs(tt->y-y1)<2*ndhi)){
	    		Arrowdot(x1,y1,tt->x,tt->y+ndhi / 3);
				if (!is_first &&(tt->prior!=NULL))  Arrowdot(tt->x+3,tt->y+2*ndhi / 3,x1+3,y1+3);
                else if (tt->prior==NULL)  drawnil(tt->x+3,tt->y+ndhi / 2);
	       		}
            else if ((tt->x<x1)&&(tt->y-y1>2*ndhi)){
            		Arrowdot(x1,y1,x1+10,y1);
            		line(x1+10,y1,x1+10,y1+ndhi*2);
            		line(x1+10,y1+ndhi*2,tt->x-10,y1+2*ndhi);
                    line(tt->x-10,y1+2*ndhi,tt->x-10,tt->y+6);
                    Arrow(tt->x-10,tt->y+6,tt->x,tt->y+6);
                    if (!is_first &&(tt->prior!=NULL)){
                    	Arrowdot(x1+8,y1+3,x1+3,y1+3);
                        line(x1+8,y1+3,x1+8,y1+ndhi*2-3);
                        line(x1+8,y1+ndhi*2-3,tt->x-12,y1+2*ndhi-3);
                        line(tt->x-12,y1+2*ndhi-3,tt->x-12,tt->y+6);
			  			Arrow(tt->x+3,tt->y+6,tt->x-12,tt->y+6);
                    	} 
                    else if (tt->prior==NULL)  drawnil(tt->x+3,tt->y+ndhi / 2);
                	}
			if (!tt->hvds){
				rectangle(tt->x,tt->y,tt->x+dndwd,tt->y+ndhi);
        		line(tt->x+ptrwd,tt->y,tt->x+ptrwd,tt->y+ndhi);
        		line(tt->x+nddtwd+ptrwd,tt->y,tt->x+nddtwd+ptrwd,tt->y+ndhi);
	    		if (!is_first||nohead){
	    			Convs(tt->data,stemp);
	    			outtextxy(tt->x+ptrwd+nddtwd / 2,tt->y+ndhi / 2-3,stemp);
	    			}
	    		else {
					setfillstyle(3, getcolor());
            		bar(tt->x+ptrwd+1,tt->y+1,tt->x+ptrwd+nddtwd-1,tt->y+ndhi-1);
            		}		
	    		tt->hvds=true;
        		dis_llist2(tp,tt->next,tt->x+dndwd-ptrwd / 2,tt->y+3,nohead,false);
    			}
    		}
    	}
}

void dis_dllist(string s,dullink tt,boolean nohead)
{
	int xl,yl,xr,yr;
	if (tt!=NULL){
		clear_dllink_range(tt);
        dllink_range(tt,xl,yl,xr,yr); 
        rectangle(xl,yl,xr,yr);
	    xl=frstcx; 
	    yl=frstcy; 
	    frstcx=tt->x; 
	    frstcy=tt->y;
	    rectangle(frstcx-20,frstcy-20,frstcx-12,frstcy+ndhi-20);
	    outtextxy(frstcx-16,frstcy-26,s);
        dis_llist2(tt,tt,frstcx-16,frstcy+4-20,nohead,true);
	    comput_dnode_card(tt,frstcx,frstcy);
	    frstcx=xl; 
	    frstcy=yl;
	    }
	else{
		rectangle(frstcx-20,frstcy-20,frstcx-12,frstcy+ndhi-20);
        outtextxy(frstcx-16,frstcy-26,s);
		drawnil(frstcx-16,frstcy-20+ndhi / 2);
		}
	getch();
}

void disp_dllisthd(string s,dullink tt,boolean havehead)
{
	if (!havehead)	dis_dllist(s,tt,true);
	else  dis_dllist(s,tt,false);
}

void  disp_card_dllist(string s,dulink l,boolean havehead,int x,int y)
{
	comput_dllist_card(l,x,y);
	disp_dllisthd(s,l,havehead);
}

void  display_dullist_from(string s,dulink &l,boolean nohead,int x,int y)
{
	int x1,y1;
	x1=frstcx;
	y1=frstcy;
	frstcx=x;
	frstcy=y;
	comput_dnode_card(l,x,y);       
	dis_dllist(s,l,nohead);
	frstcx=x1;
	frstcy=y1;   	  
	getch();
}

void  display_dullist(string s,dulink &l,boolean nohead)
{
	Into_graph(); 
	initial_llist();
	comput_dnode_card(l,frstcx,frstcy);
    	dis_dllist(s,l,nohead); 
//  ch=getchar();
}


void display_hdual_llist(string s,dulink l)
{
	display_dullist(s,l,false);
}

void display_dual_llist(string s,dulink l)
{
	display_dullist(s,l,true);
}

void  display_cchdual_llist(string s,dulink l)
{
	display_dullist(s,l,false);
}

void display_ccdual_llist(string s,dulink l)
{
	display_dullist(s,l,true);
}

void display_hdllist(string s,dulink l)
{
	display_dullist(s,l,false);
}

void display_dllist(string s,dulink l)
{
	display_dullist(s,l,true);
}

void  display_cchdllist(string s,dulink l)
{
	display_dullist(s,l,false);
}

void display_ccdllist(string s,dulink l)
{
	display_dullist(s,l,true);
}

void  create_hdllist(dulink &l)
{
	create_hdual_llist(l);
}

void  create_dllist(dulink &l)
{
	create_dual_llist(l);
}

void  create_cchdllist(dulink &l)
{
	create_cchdual_llist(l);
}

void  create_ccdllist(dulink &l)
{
	create_ccdual_llist(l);
}

void  create_dual_llist(dulink &l)
{
	dulink p;
	create_hdual_llist(l); 
	p=l;
	l=l->next;
	free(p);
	l->prior=NULL;
    comput_dllist_card(l,frstcx,frstcy);
}

void  create_cchdual_llist(dulink &l)
{
	dulink p;
	create_hdual_llist(l);
    p=l;
    while (p->next!=NULL) p=p->next;
    p->next=l;
    l->prior=p;
    comput_dllist_card(l,frstcx,frstcy);
}

void  create_ccdual_llist(dulink &l)
{
	dulink p;
	create_cchdual_llist(l);
    if (l->next==l) free(l);
    else{
    	p=l->next;
    	l->data=p->data;
    	l->next=p->next;
        p->next->prior=l; 
        free(p);
        comput_dllist_card(l,frstcx,frstcy);
      	}
}

void createlink1(link &t,FILE *ff)
{
	datatype ch;
	fscanf(ff,"%d",&ch);
	if (ch==num_of_end) t=NULL;
	else{
		if ((t=(link)malloc(sizeof(struct node)))==NULL) {
			printf("the point error!");
			exit(1);
		}
		t->data=ch;
		t->next=NULL;   
		createlink1(t->next,ff);
		}
}

void  load_hsllist_file(link &l,string ss)
{
	FILE *ff;
	if ((ff=fopen(ss,"r"))==NULL){
		printf("\nCan't open the file!");
		exit(1);
	}       
    	if ((l=(link)malloc(sizeof(struct node)))==NULL){
		printf("the linklist creating error!");
		exit(1);
		}
	l->next=NULL;
	createlink1(l->next,ff);
    	l->data=0;
    	fclose(ff);
    	Into_graph();
	comput_sllist_card(l,frstcx,frstcy);
}

void  load_cchsllist_file(link &l,string ss)
{
	link p;
	load_hsllist_file(l,ss);
	p=l;
	while (p->next!=NULL)  p=p->next;
	p->next=l;
	comput_sllist_card(l,frstcx,frstcy);
}

void  load_sllist_file(link &l,string ss)
{
	link p;
    load_hsllist_file(l,ss); 
    p=l;
    l=l->next;
    free(p);
	comput_sllist_card(l,frstcx,frstcy);
}

void  load_ccsllist_file(link &l,string ss)
{
	link p;
    load_cchsllist_file(l,ss);
    if (l->next==l) free(l);
	else{
		p=l->next;
		l->data=p->data;
		l->next=p->next;
		free(p);
		} 
    comput_sllist_card(l,frstcx,frstcy);
}

void createdulink1(dulink &pre,dulink &t,FILE *ff)
{
	datatype ch;
	fscanf(ff,"%d",&ch);
	if (ch==num_of_end)  t=NULL;
	else{
		t=(dulink)malloc(sizeof(struct dunode));
		t->prior=pre;  
		t->data=ch;
		createdulink1(t,t->next,ff);
    	}
}

void  load_hdllist_file(dulink &l,string ss)
{
	FILE *ff;
	dulink p;
    if ((ff=fopen(ss,"r"))==NULL){printf("\nCan't open the file!");exit(1);} 
	l=(dulink)malloc(sizeof(struct dunode));
	l->prior=NULL; 
	createdulink1(l,l->next,ff);
	l->data=0;
	fclose(ff);
	comput_dllist_card(l,frstcx,frstcy);
}
 
void  load_cchdllist_file(dulink &l,string ss)
{
	dulink p;
	load_hdllist_file(l,ss);   
	p=l;
    while (p->next!=NULL) p=p->next;
    p->next=l;
    l->prior=p;  
    comput_dllist_card(l,frstcx,frstcy);
}

void  load_dllist_file(dulink &l,string ss)
{
	dulink p;
    load_hdllist_file(l,ss);  
    p=l;
    l=l->next;
    free(p);
    l->prior=NULL;
	comput_dllist_card(l,frstcx,frstcy);
}



void  load_ccdllist_file(dulink &l,string ss)
{
	dulink p;
	load_cchdllist_file(l,ss);
    if (l->next==l)  free(l);
    else{
    	p=l->next;
    	l->data=p->data;
    	l->next=p->next;
        p->next->prior=l; 
        free(p); 
		} 
	comput_dllist_card(l,frstcx,frstcy);
}

void load1_sllist(link &t,int mnlknum)
{
	char ss[255]; 
	boolean selected;
	Into_graph();
	strcpy(ss,"LLists\\*.lst");
    	Loadquestion("Read SLList from ",ss,selected);
    	if (selected)
    	switch (mnlknum){
    	    case 0: load_sllist_file(t,ss);break;
            case 1: load_hsllist_file(t,ss);break;
            case 2: load_ccsllist_file(t,ss);break;
            case 3: load_cchsllist_file(t,ss);break;
        }
}

void save1_sllist(link &t,int mnlknum)
{
	char ss[255];
	boolean sv;
	strcpy(ss,"LLists\\*.lst");
	Savequestion("Save SLList to ",ss,sv);
    if (sv)
    	switch (mnlknum){
    		case 0: save_sllist_file(t,ss);break;
    		case 1: save_hsllist_file(t,ss);break;
            case 2: save_ccsllist_file(t,ss);break;
            case 3: save_cchsllist_file(t,ss);break;
    		}
}

void load1_dllist(dulink &t,int mnlknum)
{
	char ss[255]; 
	boolean selected;
	strcpy(ss,"LLists\\*.lst");
    Loadquestion("Read DLList from ",ss,selected);
    if (selected)
		switch (mnlknum){
    		case 0: load_dllist_file(t,ss);break;
			case 1: load_hdllist_file(t,ss);break;
			case 2: load_ccdllist_file(t,ss);break;
            case 3: load_cchdllist_file(t,ss);break;
	    	}
}


void save1_dllist(dulink &t,int mnlknum)
{
	char ss[255]; 
	boolean sv;
    strcpy(ss,"LLists\\*.lst"); 
    Savequestion("Save DLList to ",ss,sv);
    if (sv)
	  switch (mnlknum){
	  	case 0: save_dllist_file(t,ss);break;
        case 1: save_hdllist_file(t,ss);break;
	    case 2: save_ccdllist_file(t,ss);break;
	    case 3: save_cchdllist_file(t,ss);break;
      	} 
}

void  load_sllist(link &l)
{
	load1_sllist(l,0);
}

void  load_hsllist(link &l)
{
	load1_sllist(l,1);
}

void  load_ccsllist(link &l)
{
	load1_sllist(l,2);
}

void  load_cchsllist(link &l)
{
	load1_sllist(l,3);
}

void  load_dllist(dulink &l)
{
	load1_dllist(l,0);
}

void  load_hdllist(dulink &l)
{
	load1_dllist(l,1);
}

void  load_ccdllist(dulink &l)
{
	load1_dllist(l,2);
}

void  load_cchdllist(dulink &l)
{
	load1_dllist(l,3);
}

void write_llist(link l,boolean nohead,string ss)
{
	link p=NULL;
	boolean k; 
	int num; 
	FILE *ff;
    if ((ff=fopen(ss,"w"))==NULL){
    	printf("\nCan't open the file!");
    	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_sllist_file(link l,string ss)
{
	write_llist(l,true,ss);
}

void  save_hsllist_file(link l,string ss)
{
	write_llist(l,false,ss);
}

void  save_ccsllist_file(link l,string ss)
{
	write_llist(l,true,ss);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -