数据结构图的存储结构的输入输出
#include<iostream.h>#include<stdio.h>
#define MAXV 10
#define INF 32767
typedef struct ANode
{
int adjvex;
struct ANode *nextarc;
int weight;
}ArcNode;
typedef struct Vnode
{
InfoType info;
ArcNode *firstarc;
}VNode;
typedef struct
{
VNode adjlist[MAXV];
int n,e;
}AdjGraph;
void CreateAdj(AdjGraph *&G,int A[MAXV][MAXV],int n,int e)
{
int i,j;ArcNode *p;
G=(AdjGraph *)malloc(sizeof(AdjGraph));
for(i=0;i<n;i++)
G->adjlist[i.firstarc=NULL;
for(i=0;i<n;i++)
for(j=0;j>=0;j--)
if(A[i][j]!=0&&A[i][j]!=INF)
{
p=(ArcNode *)malloc(sizeof(ArcNode));
p->adjvex=j;
p->weight=A[i][j];
p->nextarc=G->adjlist[i].firstarc;
G->adjlist[i].firstarc=p;
}
G->n=n;G->e=e;
}
void DispAdj(AdjGraph *G)
{
int i;AreNode *p;
for(i=0;i<G->n;i++)
{
p=G->adjlist[i].firstarc;
printf("%3d[%d]->",p->adjvex,p->weight);
p=p->nextarc;
}
printf("^\n");
}
}
void main()
{
AdjGraph *G;
A[4][4]={1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,1};
CreateAdj(&G, A[MAXV][MAXV],n,e);
DispAdj(G);
}
改得头疼,刚接触这门课程,总是照着书上打,很多不懂,还在慢慢摸索,求各位大神指点改错。我的大概意思是输入,然后再输出,主函数调用