未完成的图

#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
#define INF 32767
#define MAXV 100
typedef char  InfoType;
typedef struct ANode
{
    int adjvex;
    struct ANode *nextrac;
    int weight;
}ArcNode;
typedef struct Vnode
{
   InfoType info;
   int count;
   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++)
    {
        for(j=n-1;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->nextrac=G->adjlist[i].firstarc;
            G->adjlist[i].firstarc=p;
        }
        G->n=n;G->e=n;
    }
}
void DispAdj(AdjGraph *G) //Êä³ö
{
    ArcNode *p;
    for(int i=0;i<G->n;i++)
    {
        p=G->adjlist[i].firstarc;
        printf("%3d:",i);
        while(p!=NULL)
        {

            printf("%3d[%d]->",p->adjvex,p->weight);
            p=p->nextrac;
        }
        printf("¡Ä\n");
    }
}
/*void BFS(AdjGraph *G,int v)
{
    int w,i;ArcNode *p;
    SqQueue *qu;
    InitQueue(qu);
    int visited[MAXV];
    for(i=0;i<G->n;i++) visited[i]=0;
    printf("%2d",v);
    visited[v]=1;
    enQueue(qu,v);
    while(!QueueEmpty(qu))
    {
        deQueue(qu,w);
        p=G->adjlist[w].firstarc;
        while(p!=NULL)
        {
            if(visited[p->adjvex]==0)
            {
                printf("%2d",p->adjvex);
                visited[p->adjvex]=1;
                enQueue(qu,p->adjvex);
            }
            p=p->nextrac;
        }
    }
    printf("\n");
}*/
int main()
{
   AdjGraph *G;
   int A[MAXV][MAXV]={
     {0,1,0,1,1},{1,0,1,1,0},
     {0,1,0,1,1},{1,1,1,0,1},{1,0,1,1,0}
     };
     int n,e;
     //int n=5,e=8;
     scanf("%d",&n);
     scanf("%d",&e);



          CreateAdj(G,A,n,e);
     printf("ͼGµÄÁÚ½Ó±í£º\n");  DispAdj(G);

   // BFS(G,0);
     return 1;
   }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值