#include <stdio.h>
#include "windows.h"
#define MaxVertex 5
typedef char E;
typedef struct matrixGraph {
int vertexCount, edgeCount;
int matrix[MaxVertex][MaxVertex];
E data[MaxVertex];
} *Graph;
Graph create() {
Graph graph = malloc(sizeof(struct matrixGraph));
graph->vertexCount = graph->edgeCount = 0;
for (int i = 0; i < MaxVertex; ++i)
for (int j = 0; j < MaxVertex; ++j)
graph->matrix[i][j] = 0;
return graph;
}
void addVertex(Graph graph, E element) {
if (graph->vertexCount != MaxVertex)
graph->data[graph->vertexCount++] = element;
}
void addEdge(Graph graph, int a, int b) {
if (graph->matrix[a][b] == 0){
graph->matrix[a][b] = 1;
graph->edgeCount++;
}
}
void f(Graph graph){
for (int i = -1; i < graph->vertexCount; ++i) {
for (int j = -1; j <graph->vertexCount; ++j) {
if (i == -1){
printf("%3c",'A'+j);
} else if (j == -1){
printf("%3c",'A'+i);
} else
printf("%3d",graph->matrix[i][j]);
}
printf("\n");
}
}
int main(){
Graph graph = create();
addVertex(graph,'A');
addVertex(graph,'B');
addVertex(graph,'C');
addVertex(graph,'D');
addEdge(graph,0,1);
addEdge(graph,1,2);
addEdge(graph,2,3);
addEdge(graph,3,0);
addEdge(graph,2,0);
f(graph);
}