import{_ as l,o as p,c as o,k as s,a,X as n}from"./chunks/framework.6e839c56.js";const _=JSON.parse('{"title":"Tree","description":"","frontmatter":{},"headers":[],"relativePath":"en/api/packages/datastructure/tree.md","filePath":"en/api/packages/datastructure/tree.md"}'),e={name:"en/api/packages/datastructure/tree.md"},t=s("h1",{id:"Tree",tabindex:"-1"},[a("Tree "),s("a",{class:"header-anchor",href:"#Tree","aria-label":'Permalink to "Tree"'},"​")],-1),r=s("p",null,"Tree is a collection of tree nodes. Each tree node has a value, a left pointer point to left node and a right pointer point to right node.",-1),c=s("div",{STYLE:"page-break-after: always;"},null,-1),y=s("h2",{id:"Source",tabindex:"-1"},[a("Source "),s("a",{class:"header-anchor",href:"#Source","aria-label":'Permalink to "Source"'},"​")],-1),F=s("ul",null,[s("li",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/datastructure/tree/bstree.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/datastructure/tree/bstree.go")])],-1),i=s("div",{STYLE:"page-break-after: always;"},null,-1),A=n(`<h2 id="Usage" tabindex="-1">Usage <a class="header-anchor" href="#Usage" aria-label="Permalink to &quot;Usage&quot;">​</a></h2><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,2),E=s("div",{STYLE:"page-break-after: always;"},null,-1),u=n('<h2 id="Index" tabindex="-1">Index <a class="header-anchor" href="#Index" aria-label="Permalink to &quot;Index&quot;">​</a></h2><h3 id="_1-BSTree" tabindex="-1">1. BSTree <a class="header-anchor" href="#_1-BSTree" aria-label="Permalink to &quot;1. BSTree&quot;">​</a></h3><ul><li><a href="#NewBSTree">NewBSTree</a></li><li><a href="#BSTree_Insert">Insert</a></li><li><a href="#BSTree_Delete">Delete</a></li><li><a href="#BSTree_PreOrderTraverse">PreOrderTraverse</a></li><li><a href="#BSTree_InOrderTraverse">InOrderTraverse</a></li><li><a href="#BSTree_PostOrderTraverse">PostOrderTraverse</a></li><li><a href="#BSTree_LevelOrderTraverse">LevelOrderTraverse</a></li><li><a href="#BSTree_Depth">Depth</a></li><li><a href="#BSTree_HasSubTree">HasSubTree</a></li><li><a href="#BSTree_Print">Print</a></li></ul>',3),d=s("div",{STYLE:"page-break-after: always;"},null,-1),v=n(`<h2 id="Documentation" tabindex="-1">Documentation <a class="header-anchor" href="#Documentation" aria-label="Permalink to &quot;Documentation&quot;">​</a></h2><h2 id="_1-BSTree-1" tabindex="-1">1. BSTree <a class="header-anchor" href="#_1-BSTree-1" aria-label="Permalink to &quot;1. BSTree&quot;">​</a></h2><p>BSTree is a binary search tree data structure in which each node has at two children, which are referred to as the left child and the right child. In BSTree: leftNode &lt; rootNode &lt; rightNode. Type T should implements Compare function in lancetconstraints.Comparator interface.</p><h3 id="NewBSTree" tabindex="-1"><span id="NewBSTree">NewBSTree</span> <a class="header-anchor" href="#NewBSTree" aria-label="Permalink to &quot;&lt;span id=&quot;NewBSTree&quot;&gt;NewBSTree&lt;/span&gt;&quot;">​</a></h3><p>Make a BSTree pointer instance</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">BSTree</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	root       </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">datastructure.TreeNode[T]</span></span>
<span class="line"><span style="color:#F6F6F4;">	comparator lancetconstraints.Comparator</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">TreeNode</span><span style="color:#F6F6F4;">[T any] </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	Value T</span></span>
<span class="line"><span style="color:#F6F6F4;">	Left  </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">TreeNode[T]</span></span>
<span class="line"><span style="color:#F6F6F4;">	Right </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">TreeNode[T]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> NewBSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">rootData T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> comparator lancetconstraints</span><span style="color:#999999;">.</span><span style="color:#393A34;">Comparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	root       </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">datastructure</span><span style="color:#999999;">.</span><span style="color:#393A34;">TreeNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"><span style="color:#393A34;">	comparator lancetconstraints</span><span style="color:#999999;">.</span><span style="color:#393A34;">Comparator</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">TreeNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">]</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	Value T</span></span>
<span class="line"><span style="color:#393A34;">	Left  </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">TreeNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"><span style="color:#393A34;">	Right </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">TreeNode</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree) </span><span style="color:#7B7F8B;">//</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Insert" tabindex="-1"><span id="BSTree_Insert">Insert</span> <a class="header-anchor" href="#Insert" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_Insert&quot;&gt;Insert&lt;/span&gt;&quot;">​</a></h3><p>Insert value into binary search tree</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">Insert</span><span style="color:#F6F6F4;">(data T)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Insert</span><span style="color:#999999;">(</span><span style="color:#393A34;">data T</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">PreOrderTraverse</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//6, 5, 2, 4, 7</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">PreOrderTraverse</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//6, 5, 2, 4, 7</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Delete" tabindex="-1"><span id="BSTree_Delete">Delete</span> <a class="header-anchor" href="#Delete" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_Delete&quot;&gt;Delete&lt;/span&gt;&quot;">​</a></h3><p>Delete value of binary search tree</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">Delete</span><span style="color:#F6F6F4;">(data T)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Delete</span><span style="color:#999999;">(</span><span style="color:#393A34;">data T</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Delete</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">PreOrderTraverse</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//2, 5, 6, 7</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Delete</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">PreOrderTraverse</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//2, 5, 6, 7</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="PreOrderTraverse" tabindex="-1"><span id="BSTree_PreOrderTraverse">PreOrderTraverse</span> <a class="header-anchor" href="#PreOrderTraverse" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_PreOrderTraverse&quot;&gt;PreOrderTraverse&lt;/span&gt;&quot;">​</a></h3><p>Traverse tree nodes in pre order</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">PreOrderTraverse</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">PreOrderTraverse</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">PreOrderTraverse</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//6, 5, 2, 4, 7</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">PreOrderTraverse</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//6, 5, 2, 4, 7</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="InOrderTraverse" tabindex="-1"><span id="BSTree_InOrderTraverse">InOrderTraverse</span> <a class="header-anchor" href="#InOrderTraverse" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_InOrderTraverse&quot;&gt;InOrderTraverse&lt;/span&gt;&quot;">​</a></h3><p>Traverse tree nodes in middle order</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">InOrderTraverse</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">InOrderTraverse</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">InOrderTraverse</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//2, 4, 5, 6, 7</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">InOrderTraverse</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//2, 4, 5, 6, 7</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="PostOrderTraverse" tabindex="-1"><span id="BSTree_PostOrderTraverse">PostOrderTraverse</span> <a class="header-anchor" href="#PostOrderTraverse" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_PostOrderTraverse&quot;&gt;PostOrderTraverse&lt;/span&gt;&quot;">​</a></h3><p>Traverse tree nodes in post order</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">PostOrderTraverse</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">PostOrderTraverse</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">PostOrderTraverse</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//5, 2, 4, 7, 6</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">PostOrderTraverse</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//5, 2, 4, 7, 6</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="LevelOrderTraverse" tabindex="-1"><span id="BSTree_LevelOrderTraverse">LevelOrderTraverse</span> <a class="header-anchor" href="#LevelOrderTraverse" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_LevelOrderTraverse&quot;&gt;LevelOrderTraverse&lt;/span&gt;&quot;">​</a></h3><p>Traverse tree nodes in node level order</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">LevelOrderTraverse</span><span style="color:#F6F6F4;">() []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">LevelOrderTraverse</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">LevelOrderTraverse</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//6, 5, 7, 2, 4</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">LevelOrderTraverse</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//6, 5, 7, 2, 4</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Depth" tabindex="-1"><span id="BSTree_Depth">Depth</span> <a class="header-anchor" href="#Depth" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_Depth&quot;&gt;Depth&lt;/span&gt;&quot;">​</a></h3><p>Get the depth of a binary saerch tree</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">Depth</span><span style="color:#F6F6F4;">() </span><span style="color:#97E1F1;font-style:italic;">int</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Depth</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">Depth</span><span style="color:#F6F6F4;">()) </span><span style="color:#7B7F8B;">//4</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Depth</span><span style="color:#999999;">())</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//4</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HasSubTree" tabindex="-1"><span id="BSTree_HasSubTree">HasSubTree</span> <a class="header-anchor" href="#HasSubTree" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_HasSubTree&quot;&gt;HasSubTree&lt;/span&gt;&quot;">​</a></h3><p>Check if the given tree is sub tree of origin tree or not</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">HasSubTree</span><span style="color:#F6F6F4;">(subTree </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#97E1F1;font-style:italic;">bool</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HasSubTree</span><span style="color:#999999;">(</span><span style="color:#393A34;">subTree </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    superTree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">8</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">	superTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	superTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	superTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	superTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">9</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	superTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    subTree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">	subTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	subTree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(superTree.</span><span style="color:#97E1F1;">HasSubTree</span><span style="color:#F6F6F4;">(subTree)) </span><span style="color:#7B7F8B;">//true</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(subTree.</span><span style="color:#97E1F1;">HasSubTree</span><span style="color:#F6F6F4;">(superTree)) </span><span style="color:#7B7F8B;">//false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">superTree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">8</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">	superTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	superTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	superTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	superTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">9</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	superTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">subTree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">	subTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	subTree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">superTree</span><span style="color:#999999;">.</span><span style="color:#998418;">HasSubTree</span><span style="color:#999999;">(</span><span style="color:#393A34;">subTree</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//true</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">subTree</span><span style="color:#999999;">.</span><span style="color:#998418;">HasSubTree</span><span style="color:#999999;">(</span><span style="color:#393A34;">superTree</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Print" tabindex="-1"><span id="BSTree_Print">Print</span> <a class="header-anchor" href="#Print" aria-label="Permalink to &quot;&lt;span id=&quot;BSTree_Print&quot;&gt;Print&lt;/span&gt;&quot;">​</a></h3><p>Print the structure of binary saerch tree</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (t </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">BSTree[T]) </span><span style="color:#62E884;">Print</span><span style="color:#F6F6F4;">()</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">t </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">BSTree</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">])</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Print</span><span style="color:#999999;">()</span></span></code></pre></div><p><b>Example:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    tree </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">intComparator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> (c </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">intComparator) </span><span style="color:#62E884;">Compare</span><span style="color:#F6F6F4;">(v1, v2 any) </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">	val1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v1.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	val2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> v2.(</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">-</span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	} </span><span style="color:#F286C4;">else</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> val1 </span><span style="color:#F286C4;">&gt;</span><span style="color:#F6F6F4;"> val2 {</span></span>
<span class="line"><span style="color:#F6F6F4;">		</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">1</span></span>
<span class="line"><span style="color:#F6F6F4;">	}</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> tree.</span><span style="color:#97E1F1;">NewBSTree</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">intComparator{})</span></span>
<span class="line"><span style="color:#F6F6F4;">    bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">7</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">5</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	bstree.</span><span style="color:#97E1F1;">Insert</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bstree.</span><span style="color:#97E1F1;">Print</span><span style="color:#F6F6F4;">())</span></span>
<span class="line"><span style="color:#7B7F8B;">//        6</span></span>
<span class="line"><span style="color:#7B7F8B;">//       / \\</span></span>
<span class="line"><span style="color:#7B7F8B;">//      /   \\</span></span>
<span class="line"><span style="color:#7B7F8B;">//     /     \\</span></span>
<span class="line"><span style="color:#7B7F8B;">//    /       \\</span></span>
<span class="line"><span style="color:#7B7F8B;">//    5       7</span></span>
<span class="line"><span style="color:#7B7F8B;">//   /</span></span>
<span class="line"><span style="color:#7B7F8B;">//  /</span></span>
<span class="line"><span style="color:#7B7F8B;">//  2</span></span>
<span class="line"><span style="color:#7B7F8B;">//   \\</span></span>
<span class="line"><span style="color:#7B7F8B;">//    4</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#59873A;">tree</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/datastructure/tree</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">intComparator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">c </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Compare</span><span style="color:#999999;">(</span><span style="color:#393A34;">v1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> v2 any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">int</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v1</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">val2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> v2</span><span style="color:#999999;">.(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">-</span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">else</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> val1 </span><span style="color:#AB5959;">&gt;</span><span style="color:#393A34;"> val2 </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">		</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bstree</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> tree</span><span style="color:#999999;">.</span><span style="color:#998418;">NewBSTree</span><span style="color:#999999;">(</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">intComparator</span><span style="color:#999999;">{})</span></span>
<span class="line"><span style="color:#393A34;">    bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">7</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Insert</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bstree</span><span style="color:#999999;">.</span><span style="color:#998418;">Print</span><span style="color:#999999;">())</span></span>
<span class="line"><span style="color:#A0ADA0;">//        6</span></span>
<span class="line"><span style="color:#A0ADA0;">//       / \\</span></span>
<span class="line"><span style="color:#A0ADA0;">//      /   \\</span></span>
<span class="line"><span style="color:#A0ADA0;">//     /     \\</span></span>
<span class="line"><span style="color:#A0ADA0;">//    /       \\</span></span>
<span class="line"><span style="color:#A0ADA0;">//    5       7</span></span>
<span class="line"><span style="color:#A0ADA0;">//   /</span></span>
<span class="line"><span style="color:#A0ADA0;">//  /</span></span>
<span class="line"><span style="color:#A0ADA0;">//  2</span></span>
<span class="line"><span style="color:#A0ADA0;">//   \\</span></span>
<span class="line"><span style="color:#A0ADA0;">//    4</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,63),B=[t,r,c,y,F,i,A,E,u,d,v];function C(m,g,b,h,T,f){return p(),o("div",null,B)}const k=l(e,[["render",C]]);export{_ as __pageData,k as default};
