📄 addarc.cpp
字号:
#include"traffic.h"
step Addarc(ALGraph &G)
{
CityName from,to;
int hour,minute,i = -1,j = -1,k,error = 0;
Dtime leave;
ArcNode *p;
openfile("head");
while( i == -1)
{ /*input the starte station*/
printf("please input the addarc leave station.\n");
scanf("%s",from);
i = LocateVex(G,from);
if(i == -1)
{
printf("There is no %s station\n",from);
error ++;
if(error == MAXERROR) /*too many error times*/
{
openfile("error");
return NEXTSTEP;
}
printf("please reinput:");
}
}
error = 0;
while( j == -1)
{ /*input the terminus station*/
printf("please input the addarc terminus station.\n");
scanf("%s",to);
j = LocateVex(G,to);
if(j == -1)
{
printf("There is no %s station\n",to);
error ++;
if(error == MAXERROR)
{
openfile("error");
return NEXTSTEP;
}
printf("please reinput:");
}
}
for(p = G.vertices[i].firstarc; p && p -> adjvex !=j;p = p -> nextarc); /*search the arc from i to j*/
if(!p) /*if not exist creat the arc*/
{
p = (ArcNode *) malloc(sizeof(ArcNode));
p -> adjvex = j;
p -> nextarc = G.vertices[i].firstarc;
G.vertices[i].firstarc = p;
p -> Tool[0] = NULL;
p -> Tool[1] = NULL;
}
i = -1;
error = 0;
while(i == -1)
{
printf("Which vehicle do you want to add?\n 1 train \n 2 fly\n");
scanf("%d",&i);
getchar();
if(i != 1&&i != 2) /*input error!*/
{
error ++;
if(error == MAXERROR)
{
openfile("error");
return NEXTSTEP;
}
printf("input error!please reinput!\n");
i = -1;
}
else
{
if(!p -> Tool[i-1])
{ /*the first arc , add the arc infomation*/
printf("This is the first line\n");
p -> Tool[i-1] = (Tooltype *)malloc(sizeof(Tooltype));
printf("How much money drive to %s by this tool\n",to);
scanf("%d",&p-> Tool[i-1] ->money);
printf("How long drive for %s to %s?(hour:minute)\n",from,to);
scanf("%d:%d",&p -> Tool[i-1] -> drivetime .hour,& p -> Tool[i-1] -> drivetime .minute);
p -> Tool[i-1] -> line = 0;
}
printf("please input the leave time.(hour:minute)\n");
scanf("%d:%d",&leave.hour,&leave.minute);
if(p -> Tool[i-1] ->line == MAX_LINE)
{ /*the line is Full*/
openfile("head");
printf("The line if FULL!!\nCan not add other arc!\n");
}
else
{
for(k = 0;(k < p -> Tool[i-1] -> line)&& GLtime(leave,p->Tool[i-1]->starttime[k]);k ++);
if(leave.hour == p->Tool[i-1]->starttime[k].hour &&
leave.minute == p -> Tool[i-1]->starttime[k].minute)
{
openfile("head");
printf("This line is exist!!\n");
return NEXTSTEP;
}
for(j = p -> Tool[i-1] -> line;j > k;j --)
{
p->Tool[i-1]->starttime[j].hour = p->Tool[i-1]->starttime[j-1].hour;
p->Tool[i-1]->starttime[j].minute = p->Tool[i-1]->starttime[j-1].minute;
}
p->Tool[i-1]->starttime[k].hour = leave.hour;
p->Tool[i-1]->starttime[k].minute = leave.minute;
p -> Tool[i-1] -> line ++;
openfile("head");
printf("add success!\n");
}
}
}
return NEXTSTEP;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -