[prev] 41 [next]

Exercise 9: Getting Neighbours (iii)

Assuming an adjacency list 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);