Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #ifndef GRAPH_H
  2. #define GRAPH_H
  3.  
  4. typedef struct graph Graph;
  5. typedef struct vertex Vertex;
  6. typedef struct edge Edge;
  7.  
  8. // a graph knows its order (number of vertices) and an array of pointers to
  9. // those vertices.
  10. // these values can be used, but should not be *modified* outside of graph.c.
  11. // they are read-only!
  12. struct graph {
  13.     int n, maxn;
  14.     Vertex** vertices;
  15. };
  16.  
  17. // a vertex has a label and a pointer to the first edge in its adjacency list.
  18. // these values can be used, but should not be *modified* outside of graph.c.
  19. // they are read-only!
  20. struct vertex {
  21.     char* label;
  22.     Edge* first_edge;
  23. };
  24.  
  25. // an edge knows the IDs of its two incident vertices; from u, to v
  26. // each edge also knows its weight, and points to the next edge in a list of
  27. // edges from the same vertex (or to NULL if it's the last edge in the list).
  28. // these values can be used, but should not be *modified* outside of graph.c.
  29. // they are read-only!
  30. struct edge {
  31.     int u, v;
  32.     int weight;
  33.     Edge* next_edge;
  34. };
  35.  
  36. // create a new, empty graph, with space for a maximum of n vertices
  37. Graph* new_graph(int n);
  38.  
  39. // destroy a graph, its vertices, and their edges
  40. void free_graph(Graph* graph);
  41.  
  42.  
  43. // add a new vertex with label 'name' to a graph
  44. void graph_add_vertex(Graph* graph, const char* name);
  45.  
  46. // add an undirected edge between u and v with weight w to graph
  47. void graph_add_u_edge(Graph* graph, int u, int v, int w);
  48.  
  49. // add a directed edge from u to v with weight w to a graph
  50. void graph_add_d_edge(Graph* graph, int u, int v, int w);
  51.  
  52. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement