/// <summary> /// Returns all nodes in a directed graph with no edges pointing to it. /// </summary> /// <typeparam name="TNode">Type of nodes</typeparam> /// <param name="graph">Graph with nodes</param> /// <returns>List of top nodes</returns> public static List <TNode> GetTopNodes <TNode>(this IGraph <TNode> graph) { List <TNode> nodes = graph.ToList(); for (int i = nodes.Count - 1; i >= 0; i--) { if (graph.Any(node => graph.IsEdge(node, nodes[i]))) { nodes.RemoveAt(i); } } return(nodes); }