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

📄 bfs.bak

📁 demo BFS,DFS algorithm
💻 BAK
📖 第 1 页 / 共 4 页
字号:
	outtextxy(120,40,"--------MO PHONG DANH DO THI NHAP VAO--------");
	outtextxy(180,60,"---------===(-<.>-)===---------");
	setcolor(10);
	outtextxy(30,440,"Loading");
	for(i=0;i<7;i++)
	{
		outtextxy(30+textwidth("Loading ")+4*i,440,".");
		delay(500);
	}
//=================ve do thi luc dau==========================
	tinhtoado(ctd);
	for(i=1;i<=sodinh1;i++)
	{
		ve_dinh(i,ctd[i].z,ctd[i].o);
	}
	setcolor(6);
	for(i=0;i<sodinh1;i++)
	for(j=0;j<sodinh1;j++)if(a[i][j]!=0)line(ctd[i+1].z,ctd[i+1].o,ctd[j+1].z,ctd[j+1].o);
	setcolor(10);
	outtextxy(60,460,"Continue");
	for(i=0;i<7;i++)
	{
		outtextxy(30+textwidth("Continue ")+4*i,460,".");
		delay(500);
	}
	//closegraph();
//---------------ve do thi luc da xu ly xong---------------------

	cleardevice();
	setcolor(7);
	rectangle(0,5,636,479);
	rectangle(2,7,634,477);
	setcolor(WHITE);
	outtextxy(300,40,"--------MO PHONG DUONG DI CHU TRINH HAMILTON--------");
	outtextxy(300,60,"-----------===(-<.>-)===-----------");
	setcolor(10);
	outtextxy(60,420,"Loading");
	for(i=0;i<7;i++)
	{
		outtextxy(30+textwidth("Loading ")+4*i,420,".");
		delay(500);
	}
	setcolor(10);
	if(flag==0)
	{
	    outtextxy(195,440,"Do thi tren khong co chu trinh hamilton !");
		outtextxy(50,460,"Exit ");
		for(i=0;i<6;i++)
		{
		outtextxy(30+textwidth("Exit ")+4*i,460,".");
		delay(500);
		}
	return;
	}
	for(i=1;i<=sodinh1;i++)
	{
		 ve_dinh(i,ctd[i].z,ctd[i].o);
	}
	setcolor(6);
	for(i=0;i<sodinh1;i++)
	for(j=0;j<sodinh1;j++)if(a[i][j]!=0)line(ctd[i+1].z,ctd[i+1].o,ctd[j+1].z,ctd[j+1].o);

//Ve duong noi cac dinh
	delay(1000);
	setcolor(1);
	setlinestyle(CENTER_LINE,4,3);
	for(i=0;i<sodinh1-1;i++)
	{
		line(ctd[X[i]+1].z,ctd[X[i]+1].o,ctd[X[i+1]+1].z,ctd[X[i+1]+1].o);
		delay(1000);
	}
	line(ctd[X[i]+1].z,ctd[X[i]+1].o,ctd[X[0]+1].z,ctd[X[0]+1].o);
       //	setcolor(10);
       //	outtextxy(450,470,"Bam phim bat ky de xem chu trinh Hamilton...");
       //	getch();
	//closegraph();
//----------------------------------------------------------------
       //	cleardevice();
       //	setlinestyle(SOLID_LINE,0,1);
  //	setcolor(7);
       //	rectangle(0,5,636,479);
      //	rectangle(2,7,634,477);
      //	setcolor(WHITE);
    //	outtextxy(300,40,"--------XUAT CHU TRINH HAMILTON--------");
      //	outtextxy(300,60,"---------===(-<.>-)===---------");
      //	setcolor(10);
      //	outtextxy(60,420,"Proccesing");
      //	for(i=0;i<7;i++)
     //	{
       //		outtextxy(20+textwidth("Proccessing ")+4*i,420,".");
      //		delay(500);
   //	}
	outtextxy(128,440,"==>Chu trinh Hamilton la : ");
	setcolor(YELLOW);
	for(i=0;i<sodinh1;i++)in_dinh(X[i]+1,50+textwidth("Chu trinh hamilton la : ")+12*i,440);
	in_dinh(X[0]+1,50+textwidth("Chu trinh hamilton la : ")+12*i,440);
	setcolor(10);
	outtextxy(35,460,"Exit");
	for(i=0;i<6;i++)
	{
		outtextxy(30+textwidth("Exit ")+4*i,460,".");
		delay(500);
	}

	/*int tl;
	FILE *pp;
	textcolor(YELLOW);
	gotoxy(2,4);
	cprintf("   Luu lai ?");
	textcolor(7);
	gotoxy(4,5);
	cprintf("1==> Co luu.");
	gotoxy(4,6);
	cprintf("0==> Khong luu.");
	textcolor(YELLOW);
	gotoxy(2,7);
	cprintf("   ==>Tra loi : ");
	scanf("%d",&tl);
	if(tl==1)
	{

		pp=fopen("d:/Hamilton.txt","wt");
		for(i=0;i<sodinh1;i++)fprintf(pp,"%4d",X[i]+1);
	}
	fclose(pp);
	initgraph(&man_hinh,&kieu,path);*/
       //	cleardevice();
       //	outtextxy(100,20,"Cam on ban da su dung chuong trinh nay !");

}


//=====================================================
//-----------------------case 2------------------------
void case2()
{


		cleardevice();
		reset_mouse1();
		fflush(stdin);
		setcolor(7);
		rectangle(0,5,636,479);
		rectangle(2,7,634,477);
	      //	setcolor(RED);
	      //	outtextxy(120,30,"------CHUONG TRINH TIM CHU TRINH HAMILTON------");
	      //	outtextxy(120,50,"----------TU DO THI TU VE BANG CHUOT-----------");
	      //	outtextxy(180,70,"---------===(-<.>-)===---------");
		setcolor(CYAN);
		outtextxy(30,100,"Huong dan :");
		line(25,110,30+textwidth("Huong dan :"),110);
		setcolor(YELLOW);
		outtextxy(30,120,"1.Nhap vao so dinh cua do thi.");
		outtextxy(30,140,"2.Dung chuot phai de xoa dinh va canh neu can.");
		outtextxy(30,160,"3.Dung chuot trai de tao dinh va canh noi giua cac dinh.");
		outtextxy(30,180,"4.Nhan Esc de thoat khoi viec ve do thi.");
		setcolor(RED);
		outtextxy(180,195,"---------===(-<.>-)===---------");
		setcolor(CYAN);
		outtextxy(30,210,"Nhap vao so dinh ban dau cua do thi : ");
		printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n    ==> ");
		scanf("%d",&sodinh1);
		khoi_tao_ke1(ke1);
		tinhtoado(ctd);
		vedothibandau(ctd);

		do{
		 setcolor(7);
		 rectangle(0,5,636,479);
		 rectangle(2,7,634,477);
		 sukien(banphim,chuottrai,chuotphai);
		 if(chuottrai)
		 {
		     if(xy_danhsachdinh(x1,y1,ctd,sodinh1,dinh1)&&!xy_danhsachdinh(x2,y2,ctd,sodinh1,dinh2))
			 di_chuyen_dinh(ctd,dinh1,x2,y2);
		     if(xy_danhsachdinh(x1,y1,ctd,sodinh1,dinh1)&&xy_danhsachdinh(x2,y2,ctd,sodinh1,dinh2)&&x1!=x2)
			{
			 ke1[dinh1][dinh2]=1;
			 ke1[dinh2][dinh1]=1;
			}
			if(!xy_danhsachdinh(x2,y2,ctd,sodinh1,dinh2))
			them_dinh(x2,y2);
		}
		if(chuotphai)
		if(xy_danhsachdinh(x2,y2,ctd,sodinh1,dinh1))
			xoadinh(dinh1);
		if(xy_danhsachcanh(x2,y2,dinh3,dinh4))
			   {
			    xoa_canh(dinh3,dinh4);
			    dinh3=dinh4=0;
			    }
		vedothibandau(ctd);
		} while(banphim!=13);
		setcolor(WHITE);
		rectangle(0,5,636,479);
		rectangle(2,7,634,477);

//----------------------Thiet lap ma tran ke1-----------
	for(i=0;i<sodinh1;i++)
	for(j=0;j<sodinh1;j++)a[i][j]=ke1[i+1][j+1];
//--------------Thiet lap chu trinh Hamilton-----------
	for(i=0;i<sodinh1;i++) chuaxet1[i]=1;
	v0=0;
	spt=0;
	chuaxet1[v0]=0;
	flag=0;
	Hamilton(v0);
	//closegraph();
//---------------Ve danh do thi dau vao-----------------
      //	cleardevice();
       //	setcolor(7);
       //	rectangle(0,5,636,479);
       //	rectangle(2,7,634,477);
      //	setcolor(WHITE);
       //	outtextxy(300,40,"--------MO PHONG DUONG DI CHU TRINH HAMILTON--------");
       //	outtextxy(300,60,"-----------===(-<.>-)===-----------");
       //	setcolor(10);
       //	outtextxy(60,420,"Loading");
      //	for(i=0;i<7;i++)
      //	{
	 //	outtextxy(30+textwidth("Loading ")+4*i,420,".");
	 //	delay(500);
       //	}
	setcolor(10);
	if(flag==0)
	{
		for(i=1;i<=sodinh1;i++)
		for(j=1;j<=sodinh1;j++)ke1[i][j]=0;
		outtextxy(195,25,"Do thi tren khong co chu trinh hamilton !");
	     //	outtextxy(50,460,"Exit ");
	       //	for(i=0;i<6;i++)
	    //	{
	      //	outtextxy(30+textwidth("Exit ")+4*i,460,".");
	       //	delay(500);
	      //	}

		return;
	}
	for(i=1;i<=sodinh1;i++)
	{
		ve_dinh(i,ctd[i].z,ctd[i].o);
	}
	setcolor(6);
	for(i=0;i<sodinh1;i++)
	for(j=0;j<sodinh1;j++)if(a[i][j]!=0)line(ctd[i+1].z,ctd[i+1].o,ctd[j+1].z,ctd[j+1].o);

//Ve duong noi cac dinh
	delay(1000);
	setcolor(1);
       //	setlinestyle(CENTER_LINE,4,3);
	for(i=0;i<sodinh1-1;i++)
	{
		line(ctd[X[i]+1].z,ctd[X[i]+1].o,ctd[X[i+1]+1].z,ctd[X[i+1]+1].o);
		delay(2000);
	}
	line(ctd[X[i]+1].z,ctd[X[i]+1].o,ctd[X[0]+1].z,ctd[X[0]+1].o);
       //	setcolor(10);
       //	outtextxy(450,470,"Bam phim bat ky de xem chu trinh Hamilton...");
       //	getch();
//----------------------------------------------------------------
      //	cleardevice();
       //	setlinestyle(SOLID_LINE,0,1);
      //	setcolor(7);
     //	rectangle(0,5,636,479);
     //	rectangle(2,7,634,477);
       //	setcolor(WHITE);
      //	outtextxy(300,40,"--------XUAT CHU TRINH HAMILTON--------");
      //	outtextxy(300,60,"---------===(-<.>-)===---------");
       //	setcolor(10);
       //	outtextxy(60,420,"Proccesing");
       //	for(i=0;i<7;i++)
       //	{
	//	outtextxy(20+textwidth("Proccessing ")+4*i,420,".");
	//	delay(500);
       //	}
	setcolor(10);
	outtextxy(128,465,"==>Chu trinh Hamilton la : ");
	setcolor(YELLOW);
	for(i=0;i<sodinh1;i++)in_dinh(X[i]+1,50+textwidth("==>Chu trinh hamilton la : ")+12*i,465);
	in_dinh(X[0]+1,50+textwidth("==>Chu trinh hamilton la : ")+12*(i+1),465);
       //	setcolor(10);
      //	outtextxy(35,460,"Exit");
      //	for(i=0;i<6;i++)
      //	{
	     //	outtextxy(30+textwidth("Exit ")+4*i,460,".");
	     //	delay(500);
       //	}

       //	cleardevice();

      //	outtextxy(100,20,"Cam on ban da su dung chuong trinh nay !");
	for(i=1;i<=sodinh1;i++)
	for(j=1;j<=sodinh1;j++)ke1[i][j]=0;
       //	vechuback();
       //	back_start();

}

//-------------------------------------------------------------
void welcome()
	{
//ve cac hinh chu nhat
		line(1,80,90,80);
		line(90,80,90,240);
		line(1,240,90,240);
		line(450,90,637,90);
		line(450,90,450,220);
		line(450,220,637,220);
		line(300,360,470,360);
		line(300,360,300,480);
		line(470,360,470,480);
		rectangle(1,5,637,479);
		rectangle(45,160,190,360);
		rectangle(120,260,360,400);
		rectangle(360,20,520,120);
		rectangle(420,280,600,410);
		rectangle(30,300,150,430);
		rectangle(280,180,510,310);
		rectangle(140,60,410,240);
		setlinestyle(0,0,3);
		rectangle(110,140,490,250);

//do mau vao
		setfillstyle(1,7);
		setcolor(getmaxcolor());
		floodfill(220,250,getmaxcolor());
		floodfill(20,10,getmaxcolor());
		floodfill(180,450,getmaxcolor());
		floodfill(540,450,getmaxcolor());
		floodfill(400,330,getmaxcolor());

		setfillstyle(1,15);
		floodfill(430,160,getmaxcolor());
		floodfill(275,175,getmaxcolor());
		floodfill(112,145,getmaxcolor());
		floodfill(185,165,getmaxcolor());
		floodfill(285,185,getmaxcolor());
		floodfill(112,185,getmaxcolor());
		floodfill(455,210,getmaxcolor());
		floodfill(445,185,getmaxcolor());
		floodfill(485,145,getmaxcolor());
		floodfill(200,245,getmaxcolor());
	}

//-------------------gioi thieu-----------------------
void gioithieu()
{
	    welcome();
	    setcolor(RED);
	    moveto(190,160);
	    outtext("------=====(-><-)=====------");
	    moveto(180,180);
	    outtext("DO AN MON HOC LY THUYET DO THI");
	    moveto(155,200);
	    outtext("MO PHONG DUONG DI CHU TRINH HAMILTON");
	    moveto(190,220);
	    outtext("------=====(*__*)=====------");
	    getch();
}
//----------------------------------------------------


//====================================================
//----------------------Chon menu---------------------
//====================================================
char chon()
{
	setcolor(GREEN);
	outtextxy(30,100,"Menu :");
	setcolor(WHITE);
	line(25,110,30+textwidth("Menu :"),110);
	setcolor(YELLOW);
	outtextxy(30,120,"1.Tim chu trinh Hamilton tu do thi co san trong file text...");
	delay(1000);
	outtextxy(30,140,"2.Tim chu trinh Hamilton tu do thi tu ve...");
	delay(1000);
	outtextxy(30,160,"3.Thoat khoi chuong trinh...");
	setcolor(WHITE);
	outtextxy(180,180,"---------===(-<.>-)===---------");
	setcolor(10);
	outtextxy(30,200,"Lua chon");
	line(25,210,30+textwidth("Lua chon"),210);
	return getch();
}
//======================Main()========================

void khoitao()
{
	int lc,tt;
//-------------------------------------------------
//===============Gioi thieu nhom thuc hien=========
      //	gioithieu();
      // initgraph(&man_hinh,&kieu,path);
      // cleardevice();

      // backgroundcolor
	setcolor(LIGHTBLUE);
	rectangle(0,5,636,479);
	rectangle(2,7,634,477);
	setcolor(LIGHTBLUE);
	outtextxy(120,20,"------CHUONG TRINH TIM CHU TRINH HAMILTON------");
	outtextxy(120,40,"-------------TRONG DO THI VO HUONG-------------");
	outtextxy(180,60,"---------===(-<.>-)===---------");
	vechuback();
       //	back_start();
	lc=chon();
	switch (lc)
	{
	case '1':case1();break;
	case '2':case2();break;
	case '3':start();
       //	return;
	}

}





////////////////// Phan giao dien do hoa ///////////////////////////////

void    spacemouse()
{
     _AX=0x0007;
     _CX=0;
     _DX=80*8-10;
     geninterrupt(0x33);
     _AX=0x0008;
     _CX=0;
     _DX=80*6-10;
     geninterrupt(0x33);
}


//quay tro lai giao dien
void back_interface()
{
 setfillstyle(SOLID_FILL,LIGHTBLUE);
 bar(0,0,getmaxx(),getmaxy());
 interface();
}
// Khoi tao mouse
void reset_mouse()
{
   reg.x.ax=0x0000;
   int86(0x33,&reg,&reg);
}

 //Hien thi mouse

void show_mouse()
{
   reg.x.ax=0x0001;
   int86(0x33, &reg,&reg);
}

 //An mouse

void hide_mouse()
{
   reg.x.ax=0x0002;
   int86(0x33,&reg,&reg);
}

 //Dieu khien an chuot

void ctrl_button()
{
   reg.x.ax=0x0003;
   int86(0x33,&reg,&reg);
   button=reg.x.bx;
   x=reg.x.cx;
   y=reg.x.dx;
}

//***********************************
void venut(int x1,int y1,int x2,int y2,char *s)
{
   setfillstyle(1,BLUE);
   setlinestyle(0,0,1);
   bar(x1,y1,x2,y2);
   setcolor(WHITE);
   line(x1,y1,x2,y1);
   line(x1,y1,x1,y2);
   setcolor(DARKGRAY);
   line(x2,y1,x2,y2);
   line(x2,y2,x1,y2);
   setcolor(YELLOW);
   outtextxy(x1+5,y1+5,s);
}
//************************************
void venut1(int x1,int y1,int x2,int y2,char *s)
{
   setfillstyle(1,BLUE);
   setlinestyle(0,0,1);
   bar(x1,y1,x2,y2);
   setcolor(DARKGRAY);
   line(x1,y1,x2,y1);
   line(x1,y1,x1,y2);
   setcolor(WHITE);
   line(x2,y1,x2,y2);
   line(x2,y2,x1,y2);
   outtextxy(x1+5,y1+5,s);
}

//*****************************
void gd()
{
    setlinestyle(0,0,3);
    setcolor(BROWN);
    rectangle(112,42,630,470);
    setfillstyle(BLUE,DARKGRAY);
    bar(115,45,625,465);
}
// thoat ra
void shutdow()
{
 closegraph();
 exit(1);
}
 //Tro giup
 //An nut back
void h_back_start()
{
 setfillstyle(SOLID_FILL,LIGHTGRAY);
 bar(473,453,514,466);
 setcolor(BLACK);
 outtextxy(479,457,"Back");
}

 void vechuback()
{
 setfillstyle(SOLID_FILL,WHITE);
 bar(473,453,515,467);
 setcolor(BLACK);
 outtextxy(479,457,"Back");
}
void h_back()
{
 setfillstyle(SOLID_FILL,LIGHTGRAY);
 bar(473,453,514,466);
 setcolor(BLACK);
 outtextxy(478,457,"Back");
}


//*******************************************
// thuc hien back
void back()
{
 do
 {
 ctrl_button();
 while(button==1)
   {
	ctrl_button();
	if(x>=23&&x<=70&&y>=460&&y<=475)
	  {
		hide_mouse();
		venut1(23,460,70,475,"Back");
		delay(200);
		reset_mouse();
		back_interface();
		show_mouse();
		control_program();
	}
    }
 }
while(!kbhit());
}


void start_graphics()
{
   int mh=0,mode;

	initgraph(&mh,&mode,"c:\\tc\\bgi");
	set();     //// de khoi dong chuong trinh tam thoi bi ngung
	setbkcolor(LIGHTBLUE);
	interface();
}




void gd_hamilton()
{
  setfillstyle(1,LIGHTBLUE);
  bar(0,0,getmaxx(),getmaxy());
  khoitao();
}
void start()
{

   setfillstyle(1,LIGHTBLUE);
   bar(0,0,getmaxx(),getmaxy());
   outtextxy(115,20,"Cong cu nhap");
   venut(230,15,310,30,"Ban phim");
   venut(330,15,410,30,"   File");
   venut(10,105,100,120,"Ma tran ke");
   venut(10,130,100,145,"  Do thi");
   venut(10,155,100,170,"   Hamilton");
   venut(10,180,100,195,"   Menu");
   setlinestyle(0,0,3);
   setcolor(YELLOW);
   rectangle(110,40,630,470);
   control_program_start();
}
//**********************************************************
// thuc hien back start
void back_start()
{
 show_mouse();
 do
  {
	ctrl_button();
	while(button==1)
	 {
		ctrl_button();
		if(x>=473&&x<=515&&y>=453&&y<=467)
		 {
			hide_mouse();
			h_back_start();
			delay(200);
			start();
			show_mouse();
		}
	}
  }
while(!kbhit());
}

//**********************************
//cac ham giao dien
void gd_banphim()
{
	gd();
	input(sodinh,cohuong,canh);
}
void gd_file()
{
	gd();

⌨️ 快捷键说明

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