I have been given some code to build upon and I came across a few strange structures:
typedef struct graph_t* Graph;
typedef struct vertex_t* Vertex;
struct vertex_t {
int id;
char *label;
//Implement a way to store edges...
};
struct graph_t {
/*# vertices...*/
int order;
/*# edges...*/
int size;
/*Array of vertices...*/
Vertex vertices;
};
You can probably see this is a way of storing a graph. However, what I'm confused about is the way the "Array of vertices" has been declared: Vertex vertices
. There is nothing to indicate that vertices
is actually an array, it simply seems like a single vertex (which wouldn't make sense since a graph can have many vertices).
So how can an array be declared in this way and why does this work?
Also, how would I go about initializing(?) the array and how would it be used? In the same way as a normal array?
EDIT: I forgot to add the typedefs and some missing info, it seems the fact that there is a typedef of vertex_t*
is what makes this legal?