blob: 885a8ea91529ad215451b2e0ec1a6cf87af529a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include "graph.h"
#include <stdlib.h>
#include <stdio.h>
Vertex *vertex_initialize(char label) {
Vertex *item = malloc(sizeof(Vertex));
item->label = label;
return item;
};
Graph *graph_initialize(void) {
Graph *item = malloc(sizeof(Graph));
for (int i = 0; i < 128; ++i)
item->vertices[i] = NULL;
return item;
}
Vertex *graph_add_vertex(Graph *graph, char label) {
Vertex *item = vertex_initialize(label);
graph->vertices[(int)label] = item;
return item;
}
void graph_add_edge(Graph *graph, Vertex *a, Vertex *b) {
graph->edges[a->label][b->label] = true;
}
bool graph_has_edge(Graph *graph, Vertex *a, Vertex *b) {
return graph->edges[a->label][b->label];
}
|