Logo

Programming-Idioms

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

Idiom #40 Graph with adjacency lists

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

struct Vertex
{
	float x, y, z;
	Vertex* [] adjacentVertices;
}
type Vertex struct{
	Id int
	Label string
	Neighbours map[*Vertex]bool
}

type Graph []*Vertex

The map is used as a Set of Vertex pointers.
Graph is a list of all the Vertex pointers.

New implementation...