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

📄 delarc.cpp

📁 次界面好用但是也可能有许多不足还希望有贤人志士指点迷津!
💻 CPP
字号:
#include"traffic.h"

step Delarc(ALGraph &G)
{
 ArcNode *p,*q;
 int i = -1,j = -1,k,error; 
  CityName from,to;
  openfile("head");
while(i == -1)           /*input the leave station*/
 {
  printf("whitch station of the arc you want?\nleave station:");
  scanf("%s",from);
  getchar();
  i = LocateVex(G,from);
  if(i == -1)
   {
    	    error ++;
	   if(error == MAXERROR)   /*too many  error times*/
	    {                 
	     openfile("error");
         return NEXTSTEP;
       }
    printf("there is no %s station\n",from);
    printf("please reinput!!:\n");
   }
 }//while
 
  error = 0;
 while(j == -1)          /*input the terminus station*/
  {
  printf("\nterminus station:");
  scanf("%s",to);
  getchar();
  j = LocateVex(G,to);
    if(j == -1)
   {
     error++;
     if(error == MAXERROR)
      {
        openfile("error");
        return NEXTSTEP;
      }
     printf("there is no %s station\n",to);
     printf("please reinput!\n");
   }
 }//while
 
 
  for(p = G.vertices[i].firstarc;p && p -> adjvex != j; p = p -> nextarc);  /*search  the arc*/
  if(!p)
   {
    printf("There is no line from %s to %s\n",from,to);
    return NEXTSTEP;
   }
      k = -1;
      error = 0;
   while(k == -1)
   {
    printf("Which vehicle do you want to add?\n    1 train \n    2 fly\n3 ALL\n");
    scanf("%d",&k);
    getchar();
    if(k != 1&&i != 2 && k != 3)  /*input  error!*/ 
    {
      error ++;
     if(error == MAXERROR)
	    {
	      openfile("error");
           return NEXTSTEP;
	    }
      printf("input error!please reinput!\n");
      k = -1;
    }

  else if(k == 3)     /*Delete all  the line of this arc*/
  {
     if(p == G.vertices[i].firstarc)
     {
      G.vertices[i].firstarc = p -> nextarc;
     }
    else
    {
    for(q = G.vertices[i].firstarc;q ->nextarc != p; q = q -> nextarc);
      q -> nextarc = p->nextarc;
    }
      if(p -> Tool[0])
      free(p -> Tool[0]);
      if(p -> Tool[1])
      free(p -> Tool[1]);
      free(p);
      p = NULL;
      G.arcnum--;
    printf("delete the line from %s to %s!!\n",from,to);
    return NEXTSTEP;
 }//else if k==3
 else if(k == 2 || k == 1)  /*delete the train or fly line of the arc*/
   {
     if(!p -> Tool[k-1])   /*no line of train or fly the user want to delete*/
     {
     printf("There is no this tool line from %s to %s\n",from,to);
     return NEXTSTEP;
     }
     else
      {
       printf("There are %d lines from %s to %s\n", p ->Tool[k-1] -> line,from,to);
       printf("leave time:\n");
       for(i = 0;i < p ->Tool[k-1] -> line; i++)   /*print the line of arc infomation*/
       printf("%d    %d:%d\n",i+1,p ->Tool[k-1]->starttime[i].hour,p ->Tool[k-1]->starttime[i].minute);
       
       printf("which lines do you want to delete?(%d delete all the tool lines)\n",i+1);
       scanf("%d",&i);
       if(i == p ->Tool[k-1]-> line +1)
        {
          free(p -> Tool[k-1]);
          p -> Tool[k-1] = NULL;
          printf("Delete all the tool lines from %s to %s!\n",from,to);
          return OK;
        }
       else if(i > 0 && i <=  p ->Tool[k-1] -> line)
        { 
	   for(j = i-1;j < p ->Tool[k-1] -> line-1;j++)
         {
	      p -> Tool[k-1] -> starttime[j].hour = p -> Tool[k-1] -> starttime[j+1].hour;
	      p -> Tool[k-1] -> starttime[j].minute = p -> Tool[k-1] -> starttime[j+1].minute;
         }
	 p ->Tool[k-1] -> line --;
	 if(!p ->Tool[k-1] -> line)
          {
	      free(p -> Tool[k-1]);
	      p -> Tool[k-1] = NULL;
	    if(k == 1&&!p -> Tool[1] || k == 2&&!p -> Tool[0])/*delete the line and the arc is no line */
	     {
             if(p == G.vertices[i].firstarc)             /*delete the arc*/
               {
                G.vertices[i].firstarc = p -> nextarc;
               }
             else
              {
                for(q = G.vertices[i].firstarc;q ->nextarc != p; q = q -> nextarc);
                  q -> nextarc = p->nextarc;
             }
          
          free(p);
          p = NULL;
          G.arcnum--;
          openfile("head");
          printf("delete the line from %s to %s",from,to);
          return NEXTSTEP;
	     }
	     openfile("head");
	     printf("Delete %d line!\n",i);
          return NEXTSTEP;
	     }
        printf("delete !!!\n");
        return NEXTSTEP;
      }//else
       else 
        {
         openfile("head");
	     printf("input error!!\n");
	     return NEXTSTEP;
        }
      }
  }//else k =2||k=1
 }
  return NEXTSTEP;
}

⌨️ 快捷键说明

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