\HeaderA{topological.sort}{Topological sorting of vertices in a graph}{topological.sort}
\keyword{graphs}{topological.sort}
\begin{Description}\relax
A topological sorting of a directed acyclic graph is a linear ordering
of its nodes where each node comes before all nodes to which it has
edges.
\end{Description}
\begin{Usage}
\begin{verbatim}
topological.sort(graph, mode=c("out", "all", "in"))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{graph}] The input graph, should be directed
\item[\code{mode}] Specifies how to use the direction of the edges.
For \dQuote{\code{out}}, the sorting order ensures that each node comes
before all nodes to which it has edges, so nodes with no incoming
edges go first. For \dQuote{\code{in}}, it is quite the opposite: each
node comes before all nodes from which it receives edges. Nodes 
with no outgoing edges go first.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Every DAG has at least one topological sort, and may have many.
This function returns a possible topological sort among them. If the
graph is not acyclic (it has at least one cycle), a partial topological
sort is returned and a warning is issued.
\end{Details}
\begin{Value}
A numeric vector containing vertex ids in topologically sorted order.
\end{Value}
\begin{Author}\relax
Tamas Nepusz \email{ntamas@rmki.kfki.hu} and Gabor Csardi
\email{csardi@rmki.kfki.hu} for the R interface
\end{Author}
\begin{Examples}
\begin{ExampleCode}
g <- barabasi.game(100)
topological.sort(g)
\end{ExampleCode}
\end{Examples}

