[#BloombergLP-bslalg-RbTreeUtil-isWellFormed]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslalg.adoc[bslalg]::xref:BloombergLP/bslalg/RbTreeUtil.adoc[RbTreeUtil]::isWellFormed
:relfileprefix: ../../../
:mrdocs:

Return `true` if the specified `tree` is well&hyphen;formed and refers to a valid red&hyphen;black tree, and `false` otherwise&period; For a `RbTreeAnchor` to be considered well&hyphen;formed _all_ of the following must be true&colon;

== Synopsis

Declared in `&lt;bslalg&lowbar;rbtreeutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class NODE&lowbar;COMPARATOR&gt;
static
bool
isWellFormed(
    xref:BloombergLP/bslalg/RbTreeAnchor.adoc[RbTreeAnchor] const& tree,
    NODE&lowbar;COMPARATOR const& comparator);
----

== Description

1&period; `tree&period;rootNode()` must refer to a valid red&hyphen;black tree, whose nodes are organized according to `comparator` (see `validateRbTree`)&period; 2&period; `tree&period;firstNode()` must refer to `tree&period;sentinel()` if `tree&period;rootNode()` is 0, and leftmost(tree&period;rootNode())&apos; otherwise&period; 3&period; `tree&period;nodeCount()` must be the count of nodes in `tree` (not including the sentinel node)&period; 4&period; `tree&period;sentinel()&hyphen;&gt;leftchild()` is `tree&period;rootNode()`, and (if `tree&period;rootNode()` is not 0) `tree&period;rootNode()&hyphen;&gt;parent()` is `tree&period;sentinel()`&period; 5&period; `tree&period;rootNode()` is 0 or `tree&period;rootNode()&period;isBlack()` is `true`

The behavior is undefined unless `tree&period;rootNode()` is 0 or refers to a valid binary tree&period; Note that the implementation of this function is recursive and has linear complexity with respect to the number of nodes in `tree`, it is intended for debugging purposes only&period; Note also that the final condition, that the root node be either 0 or colored black, is not a canonical requirement of a red&hyphen;black tree but an additional invariant enforced by the methods of `RbTreeUtil` to simplify the implementations&period;


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