Learn R Programming

teal.slice (version 0.5.1)

topological_sort: Topological graph sort

Description

Graph is a list which for each node contains a vector of child nodes in the returned list, parents appear before their children.

Usage

topological_sort(graph)

Arguments

graph

(named list) with node vector elements

Details

Implementation of Kahn algorithm with a modification to maintain the order of input elements.

Examples

Run this code
# use non-exported function from teal.slice
topological_sort <- getFromNamespace("topological_sort", "teal.slice")

topological_sort(list(A = c(), B = c("A"), C = c("B"), D = c("A")))
topological_sort(list(D = c("A"), A = c(), B = c("A"), C = c("B")))
topological_sort(list(D = c("A"), B = c("A"), C = c("B"), A = c()))

Run the code above in your browser using DataLab