天之道

享受编程的乐趣。
posts - 118, comments - 7, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

图的邻接表表示

Posted on 2012-08-19 20:37 hoshelly 阅读(121) 评论(0)  编辑 收藏 引用 所属分类: DS && Algorithm
#include<stdio.h>
#include<stdlib.h>
typedef struct node *link;
struct node
int v; link next; };
link NEW(int v, link next)

    link x = (link)malloc(sizeof(node));
    x->v = v; x->next = next;
    return x;
}

int main()
{
    int i,j;
    link adj[7];
    for(i=0;i<7;i++)
        adj[i] = NULL;
    while (scanf("%d%d",&i,&j) == 2)
    {
        adj[j] = NEW(i,adj[j]);
        adj[i] = NEW(j,adj[i]);
    }
    return 0;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理