This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
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.
Graph is a list of all the Vertex pointers.
type Graph[L any] []*Vertex[L]
type Vertex[L any] struct {
Label L
Neighbours map[*Vertex[L]]bool
}
The map is used as a Set of Vertex pointers.
Graph is a list of all the Vertex pointers.
The type parameter L is for arbitrary node label data.
Graph is a list of all the Vertex pointers.
The type parameter L is for arbitrary node label data.
my $G = Graph::Undirected->new(edges => [
[1,3], [2,4], [3,4], [3,5], [4,5]
]);
Adjacencies are taken care of automatically
class Vertex(set): pass
class Graph(defaultdict):
def __init__(self, *paths):
self.default_factory = Vertex
for path in paths:
self.make_path(path)
def make_path(self, labels):
for l1, l2 in zip(labels, labels[1:]):
self[l1].add(l2)
self[l2].add(l1)
G = Graph((0, 1, 2, 3), (1, 4, 2))
programming-idioms.org