aboutsummaryrefslogtreecommitdiff
path: root/src/Graph.h
diff options
context:
space:
mode:
authorJakob Lykke Andersen <Jakob@caput.dk>2025-11-29 17:01:50 +0100
committerJakob Lykke Andersen <Jakob@caput.dk>2025-11-29 17:01:50 +0100
commit9d4394e359e69010114c1ddbef8a9e7fb53c5f9e (patch)
tree8492d6a53413b95a53399297916542d77fdb386b /src/Graph.h
parent8b0e8a51f032504cc9b506ed6e5c54e996164fd0 (diff)
downloadcycle-detector-9d4394e359e69010114c1ddbef8a9e7fb53c5f9e.tar.gz
cycle-detector-9d4394e359e69010114c1ddbef8a9e7fb53c5f9e.zip
Add/update/reset files
Diffstat (limited to 'src/Graph.h')
-rw-r--r--src/Graph.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Graph.h b/src/Graph.h
new file mode 100644
index 0000000..a0087ce
--- /dev/null
+++ b/src/Graph.h
@@ -0,0 +1,40 @@
+#ifndef GRAPH_H
+#define GRAPH_H
+
+#include "LinkedList.h"
+
+typedef struct Vertex Vertex;
+typedef struct Graph Graph;
+struct Vertex {
+ int id; // a number in [0; numVertices[
+ LinkedList *outNeighbours; // A linked list of vertices.
+ LinkedList *inNeighbours; // A linked list of vertices
+};
+
+struct Graph {
+ int numVertices;
+ int numEdges;
+ Vertex *vertices; // An array of numVertices vertices
+};
+
+// Allocates and constructs a new graph with n vertices.
+// Returns a pointer to the new graph, or NULL on error.
+// Post: the caller owns the graph.
+Graph *Graph_new(int n);
+
+// Adds an edge from the i'th to the j'th vertex (0-indexed).
+void Graph_addEdge(Graph *g, int i, int j);
+
+// Reads a graph from the given file and returns a newly
+// constructed Graph representing it.
+// Returns a pointer to the read graph, or NULL on error.
+// Post: the caller owns the graph.
+Graph *Graph_read(const char *filename);
+
+// Deallocates the given graph and all its associated memory.
+void Graph_delete(Graph *g);
+
+// Prints some useful information about the given graph.
+void Graph_print(Graph *g);
+
+#endif // GRAPH_H