麻烦大家帮我看看这个题目,他为什么不输出后面的弧信息呢?
#include <stdlib.h>
#include <stdio.h>
#define max  2
typedef struct graghnode
{
int adjvex;
graghnode *next;
}graphnode,*graph;
graphnode head[max];
void Creat_M_Graph(int source,int destination)
{
     graph New,pointer;
 New=(graph)malloc(sizeof(graphnode));
 (*New).adjvex=destination;
 (*New).next=NULL;
 pointer=&head[source];
 while((*pointer).next!=NULL)
 pointer=(*pointer).next;
     (*pointer).next=New;}
void Print_Graph(graph pointer)
{
pointer=(*pointer).next;
while(pointer!=NULL)
{
printf("[%d]",(*pointer).adjvex);
pointer=(*pointer).next;
}
printf("\n");
}
void main()
{
int source;
int destination;
    int i;
graphnode head[max];
for(i=0;i<max;i++)
{
head[i].adjvex=i;
head[i].next=NULL;
}
while(1)
{ printf("请输入元数据:\n");
scanf("%d",&source);
if(source==-1)      break;
printf("请输入目的数据:\n");
scanf("%d",&destination);
if(source==destination)
{
printf("错误:自循环\n");
continue;
}
else if(source>=max||destination>=max)
{
printf("函数越界\n");
continue;
}
else Creat_M_Graph(source,destination);
 
   
}
    for(i=0;i<max;i++)
{
  printf("[%d]:",head[i]);   Print_Graph(&head[i]); }
}

解决方案 »

  1.   

    #include <stdlib.h>
    #include <stdio.h>
    #define max  2
    typedef struct graghnode
    {
        int adjvex;
        graghnode *next;
    }graphnode,*graph;
    graphnode head[max];
    void Creat_M_Graph(int source,int destination)
    {
         graph New,pointer;
         New=(graph)malloc(sizeof(graphnode));
         (*New).adjvex=destination;
         (*New).next=NULL;
         pointer=&head[source];
         while((*pointer).next!=NULL)
         pointer=(*pointer).next;
             (*pointer).next=New;}
    void Print_Graph(graph pointer)
    {
        pointer=(*pointer).next;
        while(pointer!=NULL)
        {
            printf("[%d]",(*pointer).adjvex);
            pointer=(*pointer).next;
        }
        printf("\n");
    }
    void main()
    {
        int source;
        int destination;
        int i;
        graphnode head[max];  //这里去掉
        for(i=0;i<max;i++)
        {
            head[i].adjvex=i;
            head[i].next=NULL;
        }
        while(1)
        {    printf("请输入元数据:\n");
        scanf("%d",&source);
        if(source==-1)      break;
        printf("请输入目的数据:\n");
        scanf("%d",&destination);
        if(source==destination)
        {
            printf("错误:自循环\n");
            continue;
        }
        else if(source>=max||destination>=max)
        {
            printf("函数越界\n");
            continue;
        }
        else Creat_M_Graph(source,destination);
     
       
        }
        for(i=0;i<max;i++)
        {
              printf("[%d]:",head[i]);          Print_Graph(&head[i]);    }
    }