📄 main1.c
字号:
/*the main function,use to test the graph's storage */
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<graph.c>
/*It's used to output a line of star*/
void printstar()
{
printf("\n\n****************************************************************************\n\n");
}
/*menu function,is used to display a main menu for the user to choose all kind of graph operation*/
void menu(){
cprintf("\n");
textbackground(3);/*change background color*/
printstar();
printf("\t\t\t Adjacency Lists \n\n");
printf(" use the number 1-15 to select a kind of graph operation\n");
printf("press other character to exit\n");
printf("\t1. Creat graph\n\t2. Display graph\n\t3. LocateVex\n");
printf("\t4. PutVex\n\t5. InsertVex\n\t6. DeleteVex\n\t7. GetVex\n");
printf("\t8. FirstAdjVex\n\t9. NextAdjVex\n\t10.Insert Arc\n\t11.Delete Arc\n");
printf("\t12.DFS travle\n\t13.BFS travle\n\t14.Destroy Graph\n\t15.EXIT");
printstar();
}
void main(){
int choose,x;
VertexType u,v,value;
ALGraph g;
while(1){
menu();
scanf("%d",&choose);
switch(choose){
case 1 :CreateGraph(&g);
case 2 :Display(g);getch();break;
case 3 :
{
printf("Input the vertex you want to locate:\n");
scanf("%s",&u);
Display(g);
x=LocateVex(g,u);
if(x==-1) printf("Can't find %s",u);
else printf("the locate of %s is:%d",u,x);
getch();
}
break;
case 4 :
{ Display(g);
printf("Input the vertex you want to replace:\n");
scanf("%s",&v);
printf("Input a new value:\n");
scanf("%s",&value);
PutVex(&g,v,value);
Display(g);getch();
}
break;
case 5 :
{
Display(g);
printf("Input the new vertex you want to insert:\n");
scanf("%s",&v);
InsertVex(&g,v);
Display(g); getch();
}
break;
case 6 :{
Display(g);
printf("Intput the vertex you want to delete:\n");
scanf("%s",&u);
if(LocateVex(g,u)==-1)
printf("Invalue input,the vertex is not in the graph");
DeleteVex(&g,u);
Display(g);
getch();
}
break;
case 7 :{
printf("Intput the number of the vertex you want to get\n");
printf("This number should less than %d :\n",g.vexnum);
scanf("%d",&x);
while(x>g.vexnum)
printf("Invalue input,the number should be less than%d\n",g.vexnum);
Display(g);
printf("%s",GetVex(g,x));
getch();
}
break;
case 8 :{
Display(g);
printf("Input a vertex which is in the graph:\n");
scanf("%s",&v);
x=FirstAdjVex(g,v);
if(x==-1) printf("%s has no AdjVex",v);
else printf("the locate of %s's first AdjVex is:%d",v,x);
getch();
}
break;
case 9 :{
Display(g);
printf("input a vertex and its AdjVex:\n");
scanf("%s%s",&u,&v);
x=NextAdjVex(g,u,v);
if(x==-1) printf("Can't not find %s's next AdjVex\n",v);
else printf("the locate of %s's next AdjVex is:%d",u,x);
getch();
}
break;
case 10:{
printf("Input the arc which you want to insert\n");
scanf("%s%s",&u,&v);
InsertArc(&g,u,v);
Display(g);getch();
}
break;
case 11:{ Display(g);
printf("Input the arc which you want to delete:\n");
printf("the arc's head node and tail node should be include in the graph:\n");
scanf("%s%s",&u,&v);
DeleteArc(&g,u,v);
Display(g);getch();
}break;
case 12:
Display(g);
printf("The Depth-First Search result is: ");
DFSTraverse(g,Visit);
getch();break;
case 13:
Display(g);
printf("The Breadth-First Search result is: ");
BFSTraverse(g,Visit);
getch();break;
case 14:DestroyGraph(&g);break;
default:goto label;
}
}/*creat graph*/
label: printf("\n\nEnd of Demo,thank you!");
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -