#include <stdio.h>
#include <stdlib.h>
#define INFINITY 9999
#define MAXVNUM 30
char ans;
typedef struct
{
int Vnum;
int arcs[MAXVNUM][MAXVNUM]; //图的存储结构为邻接矩阵
}Graph;
int createGraph(Graph *g,int *start,int *end)
{
int n,m,i,j,k,s,count;
int t[MAXVNUM];
printf(" ★ 请输入公交车站数和公交车数:");
scanf("%d %d",&n,&m);
if(n<=1 || m<1)
return -1;
g->Vnum = n;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
g->arcs[i][j] = INFINITY; //邻接矩阵初始化
for(s=0;s<m;s++)
{
printf("▲请输入第%d 辆公交车所途经各站的编号【0<=编号<=%d,-1 结束】:\
n",s+1,n-1);
scanf("%d",&k);
count = 0;
while(k!=-1)
{
t[count++]=k;
scanf("%d",&k);
}
for(i=0;i<count-1;i++)
{
for(j=i+1;j<count;j++) //当前线路中,从 t[i]到 t[j]有直达公交车
g->arcs[t[i]][t[j]]=1;
}
}
printf(" ★ 请输入上车站编号和下车站编号【0<=编号<=%d】:",n-1);
scanf("%d%d",start,end);
if( *start<0 || *start>n-1 || *end<0 || *end>n-1)
return -1;
- 1
- 2
前往页