赞
踩
#include<iostream>
using namespace std;
#define MaxVerterNum 100
typedef char VerterType;
typedef int EdgeType;
typedef struct
{
VerterType vexs[MaxVerterNum]; // 存储顶点
EdgeType edges[MaxVerterNum][MaxVerterNum]; // 存储邻接矩阵
int n, e; // 顶点数和边数
}MGraph;
void createMGraph(MGraph* G)
{
// 读入顶点数和边数
std::cin >> G->n >> G->e;
for (int i = 0; i < G->n; ++i)
{
//G->vexs[i] = getchar();
std::cin >> G->vexs[i];
}
// 邻接矩阵初始化
for (int i = 0; i < G->n; ++i)
{
for (int j = 0; j < G->n; ++j)
{
G->edges[i][j] = 0;
}
}
// 读入e条边,建立邻接矩阵
int i, j;
for (int k = 0; k < G->e; ++k)
{
//读入边<vi,vj>
std::cin >> i >> j;
G->edges[i][j] = 1;
G->edges[j][i] = 1;
}
}
int main()
{
MGraph* pg = new MGraph;
createMGraph(pg);
// 打印pg图中的节点连接情况
for (int i = 0; i < pg->n; ++i)
{
for (int j = 0; j < pg->n; ++j)
{
std::cout << pg->edges[i][j] << "\t";
}
std::cout << endl;
}
delete pg;
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。