输出很奇怪,请问如何解决呢?
#include<stdio.h>
#include<stdlib.h>
#define MAX 6
struct node
{
int adjvex;
struct node *next;
};
typedef struct node edgenode;
struct hnode
{
int info;
edgenode *link;
};
typedef struct hnode headnode;
headnode data[MAX];
void createlist ()
{
int i,j,k;
edgenode *s;
int num,e;
printf("一共有多少条边");
scanf("%d",&e);
for(i=1;i<MAX;i++)
{
printf("输入顶点");
scanf("%d",&num);
data[i].info=num;
data[i].link=NULL;
}
for(k=1;k<=e;k++)
{
printf("输入边的两个顶点");
scanf("%d%d",&i,&j);
s=(edgenode *)malloc(sizeof(edgenode));
if(s!=NULL)
{
s->adjvex=j;
s->next=data[i].link;
data[i].link=s;
}
s=(edgenode *)malloc(sizeof(edgenode));
if(s!=NULL)
{
s->adjvex=i;
s->next=data[j].link;
data[j].link=s;
}
}
}
void printf_list ()
{
int i;
edgenode *pointer;
for(i=1;i<MAX;i++)
{
printf("顶点表:%d",data[MAX].info);
pointer=data[MAX].link;
while(pointer!=NULL)
{
printf("%d",pointer->adjvex);
pointer=pointer->next;
}
}
}
int main()
{
createlist();
printf_list();
}