pub fn topological_sort<T, S>(graph: &S) -> SparseResult<Vec<usize>>
Expand description
Topological sort of a directed acyclic graph (DAG)
§Arguments
graph
- The directed graph as a sparse matrix
§Returns
Topologically sorted order of vertices, or error if the graph has cycles
§Examples
use scirs2_sparse::csgraph::topological_sort;
use scirs2_sparse::csr_array::CsrArray;
// Create a DAG: 0 -> 1 -> 2
let rows = vec![0, 1];
let cols = vec![1, 2];
let data = vec![1.0, 1.0];
let graph = CsrArray::from_triplets(&rows, &cols, &data, (3, 3), false).unwrap();
let topo_order = topological_sort(&graph).unwrap();