刚开始学习数据结构中的图,记录一下,方便后续的学习
#include<iostream>
using namespace std;
#define MAXVEX 100
struct MGrahp
{
char *vertexs;//顶点矩阵
int **edges;//邻接矩阵
int verterNum, edgeNum;
};
void createGraph(MGrahp *G)
{
cout << "输入图节点数、边数:\n";
cin >> G->verterNum>>G->edgeNum;
G->vertexs = new char[G->verterNum];
G->edges = new int*[G->verterNum];
for (int i = 0; i < G->verterNum; i++)
G->edges[i] = new int[G->verterNum];
for (int i = 0; i < G->verterNum; i++)
{
for (int j = 0; j < G->verterNum; j++)
{
if (i == j)
G->edges[i][j] = 0;
else
{
G->edges[i][j] = INT_MAX;
}
}
}
cout << "输入顶点" << endl;
for (int i = 0; i < G->verterNum; i++)
{
cout << "输入第" << i + 1 << "个顶点:";
cin >> G->vertexs[i];
}
cout << "输入边的顶点下标和权重:\n";
int x, y, w;
for (int j = 0;