Chinaunix首页 | 论坛 | 博客
  • 博客访问: 426853
  • 博文数量: 103
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 971
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-11 17:22
文章分类
文章存档

2008年(77)

2007年(26)

我的朋友

分类: C/C++

2007-12-22 23:38:35


static void bfs(algraph* g, int k)
{
        queue* p = NULL;
        edgenode* node;
        int val;

        initqueue(&p);
        printf("%d ", g->adjlist[k].vertex);
        visited[k] = 1;
        enqueue(&p, k);

        while(!emptyqueue(&p)){
                delqueue(&p, &val);
                node = g->adjlist[val].firstedge;
                while(node != NULL){
                        if(!visited[node->adjvex]){
                                visited[node->adjvex] = 1;
                                printf("%d ", node->adjvex);
                                enqueue(&p, node->adjvex);
                        }
                        node = node->next;
                }
        }
}

阅读(1126) | 评论(0) | 转发(0) |
0

上一篇:聂小凤

下一篇:循环队列操作实现

给主人留下些什么吧!~~