[#BloombergLP-bdlb-TopologicalSortUtil-sort-04]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlb.adoc[bdlb]::xref:BloombergLP/bdlb/TopologicalSortUtil.adoc[TopologicalSortUtil]::sort
:relfileprefix: ../../../
:mrdocs:

Sort the elements of `NODE&lowbar;TYPE` in topological order determined by the specified `relations` and load the resulting linear ordered set to the specified `result`&period; If the sort is unsuccessful, load the elements that have not been ordered to the specified `unsorted` list&period; The input relations are provided as pairs of the form (U, V) where U precedes V in the output&period; Return `false` if sort fails due to a cycle in the input else return `true` if sort successful&period; Note that even if the method returns `false`, `result` may contain a subset of elements in the right topological order, essentially elements that the routine was able to sort before the cycle was discovered and `unsorted` will contain the elements that the routine was unable to sort&period;

== Synopsis

Declared in `&lt;bdlb&lowbar;topologicalsortutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class NODE&lowbar;TYPE&gt;
static
bool
sort(
    xref:bsl/vector-00d.adoc[bsl::vector&lt;NODE&lowbar;TYPE&gt;]* result,
    xref:bsl/vector-00d.adoc[bsl::vector&lt;NODE&lowbar;TYPE&gt;]* unsorted,
    xref:bsl/vector-00d.adoc[bsl::vector&lt;bsl::pair&lt;NODE&lowbar;TYPE, NODE&lowbar;TYPE&gt;&gt;] const& relations);
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
