summaryrefslogtreecommitdiff
path: root/src/03/graph.c
blob: 1e672022734ac6cd57d759a6ef8c7a6810547a16 (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
#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;
}