[prev] 34 [next]

Exercise 7: Getting Neighbours (ii)

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