/**
* Adjacency list for directed graph.
*
* @author Fan Min minfanphd@163.com.
*/
#include <stdio.h>
#include <malloc.h>
#define QUEUE_SIZE 10
/*************** Copied code begins *****************/
int* visitedPtr;
/**
* The structure of a graph.
*/
typedef struct Graph{
int** connections;
int numNodes;
} *GraphPtr;
/**
* Initialize a graph.
*/
GraphPtr initGraph(int paraSize, int** paraData) {
int i, j;
GraphPtr resultPtr = (GraphPtr)malloc(sizeof(struct Graph));
resultPtr -> numNodes = paraSize;
//resultPtr -> connections = (int**)malloc(paraSize * paraSize * sizeof(int));
resultPtr -> connections = (int**)malloc(paraSize * sizeof(int*));
for (i = 0; i < paraSize; i ++) {
resultPtr -> connections[i] = (int*)malloc(paraSize * sizeof(int));
for (j = 0; j < paraSize; j ++) {
resultPtr -> connections[i][j] = paraData[i][j];
}//Of for j
}//Of for i
return resultPtr;
}//Of initGraph
/**
* A queue with a number of indices.
*/
typedef struct GraphNod
数据结构 ---- 邻接表及广度优先遍历***
最新推荐文章于 2022-12-28 22:27:09 发布
![](https://img-home.csdnimg.cn/images/20240709112858.png)