Function topologicSort

  • Topologically sort an iterable of edges.

    Type Parameters

    • T

    Parameters

    • edges: Iterable<[T, T]>

      The iterable object of edges to sort. An edge is represented as a 2-tuple of [fromNode, toNode].

    Returns T[]

    The topologically sorted array of nodes.

    Notes

    If a cycle is present in the graph, the cycle will be ignored and the return value will be only approximately sorted.

    Example

    import { topologicSort } from '@lumino/algorithm';

    let data = [
    ['d', 'e'],
    ['c', 'd'],
    ['a', 'b'],
    ['b', 'c']
    ];

    topologicSort(data); // ['a', 'b', 'c', 'd', 'e']