Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- const char* city_name;
- } GraphNode;
- typedef struct {
- unsigned int node_a;
- unsigned int node_b;
- } GraphEdge;
- #define MAX_GRAPH_NODE_COUNT 1024
- #define MAX_GRAPH_EDGE_COUNT 2048
- int main(void) {
- GraphNode nodes[MAX_GRAPH_NODE_COUNT]; // Node array
- GraphEdge edges[MAX_GRAPH_EDGE_COUNT]; // Edge array
- int node_count = 2;
- int edge_count = 1:
- GraphNode node_a = {"London"};
- GraphNode node_b = {"Birmingham"};
- memcpy(&nodes[0], node_a, sizeof(node_a)); // Put node at index 0, so id = 0 for Node A aka London
- memcpy(&nodes[1], node_a, sizeof(node_b)); // Put node at index 1, so id = 1 for Node B aka Birmingham
- edges[0] = {0, 1}; // Edge 0 connects London and Birmingham aka Node A and B aka node[0] and node[1].
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement