第1关:实现图的宽度优先遍历
本关任务:请你实现 graph.cpp 里的int Graph_WidthFirst(Graph*g, int start, Edge* tree)
函数。 注意遵守约定:编号小的优先入队列。
相关知识
图 2 给出了对图 1 的无向图的存储结构图:每个顶点的名称由一个字符串描述,所有字符串的起始地址组织为一个数组,数组的起始地址为vetex
;顶点的相邻关系保存在相邻矩阵中,其起始地址为adj
,adj[i*n+j]
的值为 1 表示i
号顶点到j
号顶点有边,为 0 表示无边,其中n
是顶点个数,i
和j
是顶点在顶点表中的编号。
//Graph
///
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Graph.h"
/
Graph* Graph_Create(int n)
{
Graph* g=(Graph*)malloc(sizeof(Graph));
g-&