[prev] 25 [next]

Exercise 5: Getting Neighbours (i)

Assuming an array-of-edges representation ...

Write a function to give a list of all vertices connected to a given vertex

Vertex *neighbours(Graph g, Vertex v, int *nv);

which

  • returns a dynamically allocated array of vertices (vs)
  • sets the value of the nv parameter to size of array
Usage:

Graph g;  Vertex v;  int n;
...
Vertex *ns = neighbours(g, v, &n);