Created
January 9, 2018 23:42
-
-
Save CallumHoward/110372eaf4cf6af274056ec6d6504567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include "Graph.h" | |
bool isAdjacentEdge(Edge a, Edge b); | |
bool isPath(Edge path[], int pathSize); | |
bool hasDuplicates(Edge edges[], int numEdges); | |
bool sameEdge(Edge a, Edge b); | |
bool isEulerPath(Graph g, Edge path[], int pathSize) { | |
assert(g != NULL); | |
// includes all edges in the graph | |
// is actually a path, the edges connect up | |
// check there are no duplicate edges in the path | |
return true; | |
} | |
bool sameEdge(Edge a, Edge b) { | |
return a.v == b.v && a.w == b.w; | |
} | |
bool isAdjacentEdge(Edge a, Edge b) { | |
return a.w == b.v || a.v == b.w; | |
} | |
bool isPath(Edge path[], int pathSize) { | |
for (int i = 0; i < pathSize - 1; i++) { | |
if (!isAdjacentEdge(path[i], path[i + 1])) { return false; } | |
} | |
return true; | |
} | |
bool hasDuplicates(Edge edges[], int numEdges) { | |
// for every edge in the array | |
for (int i = 0; i < numEdges; i++) { | |
// for every other edge in the array | |
for (int j = i + 1; j < numEdges; j++) { | |
// check that the two edges are not the same | |
if (sameEdge(edges[i], edges[j])) { return true; } | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment