Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #40 Graph with adjacency lists

Declare a Graph data structure in which each Vertex has a collection of its neighbouring vertices.

use Graph::Undirected qw();
my $G = Graph::Undirected->new(edges => [
    [1,3], [2,4], [3,4], [3,5], [4,5]
]);

Adjacencies are taken care of automatically
struct Vertex
{
	float x, y, z;
	Vertex* [] adjacentVertices;
}

New implementation...