我们做了一个电网建设造价模拟系统的C程序,编译有1个错,实在是找不到错在哪里,求大虾帮助。
发布网友
发布时间:2022-05-14 18:15
我来回答
共2个回答
热心网友
时间:2023-10-20 00:55
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <iostream>
using namespace std;
//#define INFINITY INT_MAX
#define MAX_VERTEX_NUM 20
typedef int VRtype;
typedef int Infotype;
typedef char Vertextype;
typedef struct Arccell
{
VRtype adj;
Infotype *info;
}Arccell,Adjmatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct
{
Vertextype vexs[MAX_VERTEX_NUM];
Adjmatrix arcs;
int vexnum,arcnum;
}MGraph;
typedef struct
{
Vertextype adjvex;
VRtype lowcost;
}closedge[MAX_VERTEX_NUM];
int Locatevex(MGraph &G,Vertextype u);
int minimum(closedge close);
void CreatUDN(MGraph G)
{
int weigh;
int i,j=0,k=0;
char hand,tide;
printf("input the number of vertex & arcnum:");
scanf("%d,%d",&G.vexnum,&G.arcnum);
printf("shuru tu de quan,shuzi daibiao lujing changan,0 daibiao meiyou da.");
for(i=0;i<G.vexnum;i++)
{
for(j=0;j<G.vexnum;j++)
scanf("%d",G.arcs[i][j].info);
}
printf("\n");
printf("input %d char for vexs:",G.vexnum);
for(i=0;i<G.vexnum;i++)
scanf("%s",&G.vexs[i]);
printf("\n");
printf("input %d arc(char,char,int)\n",G.arcnum);
j=0;
k=0;
for(i=0;i<G.arcnum;i++)
{
printf("%d:",i);
scanf("%c",&hand);
scanf("%c",&tide);
scanf("%d",&weigh);
while(hand!=G.vexs[j])
j++;
while(tide!=G.vexs[k])
k++;
G.arcs[j][k].adj=weigh;
G.arcs[k][j].adj=weigh;
j=0;
k=0;
printf("\n");
}
}
void Minispantree_PRIM(MGraph &G,Vertextype u)
{
int i,j,k=0;
closedge close;
k=Locatevex(G,u);
for(j=0;j<G.vexnum;j++)
{
if(j!=k)
{
close[j].adjvex=G.vexs[k];
close[j].lowcost=G.arcs[k][j].adj;
}
}
close[j].lowcost=88;
close[j].adjvex='\0';
close[k].lowcost=0;
close[k].adjvex=u;
for(i=1;i<=G.vexnum;i++)
{
k=minimum(close);
printf("%",close[k].adjvex);
printf("--------");
printf("%c ",G.vexs[k]);
close[k].lowcost=0;
for(j=0;j<=G.vexnum;j++)
{
if(G.arcs[k][j].adj<close[j].lowcost)
{
close[j].adjvex=G.vexs[k];
close[j].lowcost=G.arcs[k][j].adj;
}
}
}
}
int Locatevex(MGraph &G,Vertextype u)
{
int k=0;
while(G.vexs[k++]==u)
return k-1;
return 0;
}
int minimum(closedge close)
{
int j1=0,client = INT_MAX,j2;
while(close[j1].adjvex!='\0')
{
if(client>close[j1].lowcost&&close[j1].lowcost!=0)
{
client=close[j1].lowcost;
j2=j1;
}
j1++;
}
return j2;
}
void main()
{
int i, j;
MGraph G;
CreatUDN(G);
for(i = 0; i <= G.vexnum; i++)
{
for(j = 0; j <= G.vexnum; j++)
{
printf("%d",G.arcs[i][j].adj);
printf(" ");
}
printf("\n");
}
Minispantree_PRIM(G,'a');
}
就按照上面的代码执行,不会出错,但是我不知道是否能够达到你想要的结果
热心网友
时间:2023-10-20 00:56
我来了
错了 两个return 还有好几个变量
还有 两个函数没有在使用前声明追问能详细说明哪几个变量错了吗?