求邻接表的算法问题,高手请进
											帮忙用c写邻接表建立和输出的代码  谢谢										
					
	
				
											#include <stdio.h>
#include <stdlib.h>
typedef int VertexType;
typedef struct ArcNode//表结点
{
    int adjvex;//弧所指向的顶点的位置
    struct ArcNode *nextarc;
}ArcNode;
typedef struct VNode//头结点
{
    VertexType data;//顶点信息
    ArcNode *firstarc;//指向第一条依附该弧的顶点指针
}VNode,*AdjList;
typedef struct
{
    AdjList vertices;
    int vexnum;//图的**当前**顶点数
}ALGraph;
/////创建图的邻接矩阵
void CreatAjacentMatrix(int *array,int n)//创建邻接矩矩阵(n行n列)
{
    int a;
    int i,j,flag=0;
    printf("请输入一个%d行%d列的关于图的邻接矩阵:\n",n,n);
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        {
            scanf("%d",&a);
            *(array+i*n+j)=a;
        }    
}
void PrintAjacentMatrix(int *array,int n)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            printf("%5d ",*(array+i*n+j));
        printf("\n");
    }
}
////将邻接矩阵导出为图的邻接表形式
void CreatAdjList(int *array,int n,ALGraph *G)
{
    int i,j;
    ArcNode *p;//表结点
    G->vexnum=n;//初始化顶点数
    G->vertices=(VNode *)malloc((n+1)*sizeof(VNode));//头结点数组,开辟n+1长度的数组空间
    for(i=1;i<=n;i++)//初始化头结点数组
    {
        G->vertices[i].data=i;
        G->vertices[i].firstarc=NULL;
    }
    //////////
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        {
            if(*(array+i*n+j)==1)
            {
                p=(ArcNode *)malloc(sizeof(ArcNode));
                p->adjvex=j+1;
                p->nextarc=G->vertices[i+1].firstarc;
                G->vertices[i+1].firstarc=p;
            }
        }
}
void main()
{
    int n;
    int *A;
    ALGraph G;
    printf("请输入你想创建的邻接矩矩阵的行列数(即顶点数):\n");
    scanf("%d",&n);
    A=(int *)malloc(n*n*sizeof(int));
    CreatAjacentMatrix(A,n);
    printf("请输出图的邻接矩阵A:\n");
    PrintAjacentMatrix(A,n);
    CreatAdjList(A,n,&G);
}										
					
	
	
	
	      


											

	    

	

