gert-topo-sort

Topologically sort Gert graphs

Usage no npm install needed!

<script type="module">
  import gertTopoSort from 'https://cdn.skypack.dev/gert-topo-sort';
</script>

README

gert-topo-sort

Topologically sort Gert graphs

Build Status Coverage Status

Usage

var Graph = require('gert').Graph;
var TopoSort = require('gert-topo-sort');

var graph = new Graph({
    directed: true,
    vertices: {
        'Nap': [],
        'Make Toast': ['Eat breakfast'],
        'Pour juice': ['Eat breakfast'],
        'Eat breakfast': ['Nap']
    }
});

// ['Pour juice', 'Make Toast', 'Eat breakfast', 'Nap']
var morning = TopoSort(graph);

API

TopoSort(graph)

Returns an array of topologically sorted vertex ids from the directed, acyclic graph. If graph is undirected or cyclic, TopoSort() will throw an error.