
#include <iostream>
using namespace std;
# define MAXVERTEX_NUMS 20
class Vertex
{
public:
Vertex(const int& dt): data(dt) { }
private:
char data;
};
class Graph
{
public:
Graph(): nVertex(0)
{
for(int i=0; i<MAXVERTEX_NUMS; i++)
for(int j=0; j<MAXVERTEX_NUMS; j++)
adjMat[i][j] = 0;
}
void addVertex(const char& v);
void addEdge(const char& st, const char& end);
void print() const;
~Graph()
{
for(int i=0; i<nVertex; i++)
delete vertexTable[i];
}
private:
Vertex* vertexTable[MAXVERTEX_NUMS];
bool adjMat[MAXVERTEX_NUMS][MAXVERTEX_NUMS];
int nVertex;
};
void Graph::addVertex(const char& v)
{
vertexTable[nVertex] = new Vertex(v);
nVertex++;
}
void Graph::addEdge(const char& st, const char& end)
{
adjMat[st-65][end-65] = 1;
adjMat[end-65][st-65] = 1;
}
void Graph::print() const
{
for(int i=0; i<nVertex; i++)
{
for(int j=0; j<nVertex; j++)
std::cout << adjMat[i][j] << " ";
std::cout << endl;
}
}
int main()
{
Graph G;
G.addVertex('A');
G.addVertex('B');
G.addVertex('C');
G.addVertex('D');
G.addVertex('E');
G.addEdge('A', 'B');
G.addEdge('A', 'D');
G.addEdge('B', 'E');
G.addEdge('D', 'E');
G.addEdge('C', 'E');
G.print();
return 0;
}