/
graph.h
45 lines (35 loc) · 1.18 KB
/
graph.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// graph.h
// adjacencylist
//
// Created by Sam Goldman on 6/21/11.
// Copyright 2011 Sam Goldman. All rights reserved.
//
#include "list.h"
typedef struct Edge {
struct Vertex *vertex;
double weight;
} Edge;
typedef struct Vertex {
void *data;
struct List *edges;
} Vertex;
typedef struct Graph {
struct List *vertices;
int count;
} Graph;
Graph *graph_create(void);
Vertex *vertex_create(void *data);
Edge *edge_create(Vertex *vertex, double weight);
void graph_add_vertex(Graph *graph, Vertex *vertex);
void graph_add_vertex_sorted(Graph *graph, Vertex *vertex, int(*cmp)(const void *a, const void *b));
void graph_remove_vertex(Graph *graph, Vertex *vertex);
void vertex_add_edge(Vertex *vertex, Edge *edge);
void vertex_add_edge_sorted(Vertex *vertex, Edge *edge);
void vertex_remove_edge(Vertex *vertex, Edge *edge);
void vertex_add_edge_to_vertex(Vertex *from, Vertex *to, double weight);
void vertex_add_edge_to_vertex_sorted(Vertex *from, Vertex *to, double weight);
void vertex_remove_edge_to_vertex(Vertex *from, Vertex *to);
void graph_sort_vertices(Graph *graph, int(*cmp)(const void *a, const void *b));
void vertex_sort_edges(Vertex *vertex);
void graph_free(Graph *graph);