c++程序与结构体有关的问题

来源:百度知道 编辑:UC知道 时间:2024/07/07 20:47:11
#include<iostream>
using namespace std;
#define Max 100
typedef struct ArcNode {
int adjvex;
struct ArcNode *nextarc;
int rprice;
}ArcNode;
typedef struct VNode {
int price;
int L;
int num;
ArcNode *firstarc;
}VNode;
VNode AdjList[Max];
int sum=INT_MAX;
int s=0;
void summ(VNode *AdjList,int i)
{
ArcNode *q;
q=AdjList[i].firstarc;
if(AdjList[i].firstarc!=NULL)
{
do
{
s+=AdjList[i].firstarc->rprice;
if(sum>s+AdjList[AdjList[i].firstarc->adjvex].price)
sum=s+AdjList[AdjList[i].firstarc->adjvex].price;
summ(AdjList,AdjList[i].firstarc->adjvex);
q=q->nextarc;
}while(q!=NULL);
}
else
{
if(sum>s+AdjList[i].price)
sum=s+AdjList[i].price;
}
}
int main()
{
int i,j;
int n,o;
ArcNode *p;<

我刚刚又研究了一下,你的结构指针firstarc还没有指向的对象,in other word ,firstarc是一个野指针,还未初始化。因此,你每次循环时,要因要给firstarc一个指向的对象——结构ArcNode的对象。