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

`sort` overloads

== Synopses

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

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;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class NODE&lowbar;TYPE&gt;
static
bool
xref:BloombergLP/bdlb/TopologicalSortUtil/sort-04.adoc[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]#xref:BloombergLP/bdlb/TopologicalSortUtil/sort-04.adoc[_» more&period;&period;&period;_]#

Sort the input elements in topological order and write the resulting linear ordered set into the specified `resultOutIter`&period; If the sort is unsuccessful (the input is not an acyclic directed graph) write the elements that have not been sorted to the specified `unsortedOutIter` output&period; The input elements are provided as a sequence of (conceptual or physical) pairs between the specified `relationsBegin` and `relationsEnd` of the form (U, V), where U and V are nodes, and U precedes V in the output&period; Return `true` on success, and `false` if the sort fails due to a cycle in the input&period; The type `bsl&colon;&colon;iterator&lowbar;traits&lt;INPUT&lowbar;ITER&gt;&colon;&colon;value&lowbar;type` must either be `bsl` or `std&colon;&colon;pair` where the `first&lowbar;type` and `second&lowbar;type` are the same as `bsl&colon;&colon;iterator&lowbar;traits&lt;OUTPUT&lowbar;ITER&gt;&colon;&colon;value&lowbar;type` or `TopologicalSortUtilEdgeTraits` must be specialized for the type, i&period;e&period;, the supplied `bsl&colon;&colon;iterator&lowbar;traits&lt;INPUT&lowbar;ITER&gt;&colon;&colon;value&lowbar;type` must support the following syntax&colon; &grave; typedef typename bsl&colon;&colon;iterator&lowbar;traits&lt;INPUT&lowbar;ITER&gt;&colon;&colon;value&lowbar;type IterValue&semi; typedef typename bsl&colon;&colon;iterator&lowbar;traits&lt;RESULT&lowbar;ITER&gt;&colon;&colon;value&lowbar;type ResultValue&semi;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class INPUT&lowbar;ITER,
    class OUTPUT&lowbar;ITER,
    class UNSORTED&lowbar;OUTPUT&lowbar;ITER&gt;
static
bool
xref:BloombergLP/bdlb/TopologicalSortUtil/sort-03.adoc[sort](
    INPUT&lowbar;ITER relationsBegin,
    INPUT&lowbar;ITER relationsEnd,
    OUTPUT&lowbar;ITER resultOutIter,
    UNSORTED&lowbar;OUTPUT&lowbar;ITER unsortedOutIter);
----

[.small]#xref:BloombergLP/bdlb/TopologicalSortUtil/sort-03.adoc[_» more&period;&period;&period;_]#


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