Advertisement
Guest User

Untitled

a guest
May 15th, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. typedef struct {
  2.    const char* city_name;
  3. } GraphNode;
  4.  
  5. typedef struct {
  6.     unsigned int node_a;
  7.     unsigned int node_b;
  8. }  GraphEdge;
  9.  
  10. #define MAX_GRAPH_NODE_COUNT 1024
  11. #define MAX_GRAPH_EDGE_COUNT 2048
  12.  
  13.  
  14. int main(void) {
  15.   GraphNode nodes[MAX_GRAPH_NODE_COUNT]; // Node array
  16.   GraphEdge edges[MAX_GRAPH_EDGE_COUNT]; // Edge array
  17.  
  18.   int node_count = 2;
  19.   int edge_count = 1:
  20.  
  21.   GraphNode node_a = {"London"};
  22.   GraphNode node_b = {"Birmingham"};
  23.  
  24.   memcpy(&nodes[0], node_a, sizeof(node_a)); // Put node at index 0, so id = 0 for Node A aka London
  25.   memcpy(&nodes[1], node_a, sizeof(node_b)); // Put node at index 1, so id = 1 for Node B aka Birmingham
  26.  
  27.   edges[0] = {0, 1}; // Edge 0 connects London and Birmingham aka Node A and B aka node[0] and node[1].  
  28.  
  29.   return 0;
  30. }
Tags: graph
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement