<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>XSLT: Riding the challenge</title>
	<atom:link href="http://dnovatchev.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dnovatchev.wordpress.com</link>
	<description>Discover another world . . .</description>
	<lastBuildDate>Sun, 29 Jan 2012 21:32:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dnovatchev.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/aee8ca88dd8f899bce459443b9386fbb?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>XSLT: Riding the challenge</title>
		<link>http://dnovatchev.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dnovatchev.wordpress.com/osd.xml" title="XSLT: Riding the challenge" />
	<atom:link rel='hub' href='http://dnovatchev.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The set datatype implemented in XPath 3.0</title>
		<link>http://dnovatchev.wordpress.com/2012/01/12/the-set-datatype-implemented-in-xpath-3-0/</link>
		<comments>http://dnovatchev.wordpress.com/2012/01/12/the-set-datatype-implemented-in-xpath-3-0/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 12:30:36 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[functional data structures]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[XPath 3.0]]></category>

		<guid isPermaLink="false">https://dnovatchev.wordpress.com/?p=84</guid>
		<description><![CDATA[In my previous two posts I introduced the binary search tree datatype, implemented in XPath 3.0. In most cases the binary search tree operations find, insert and delete have efficiency of O(log(d)) and the print/serialize operation is O(N*log(d)), where d &#8230; <a href="http://dnovatchev.wordpress.com/2012/01/12/the-set-datatype-implemented-in-xpath-3-0/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=84&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my previous two posts I introduced the binary search tree datatype, implemented in XPath 3.0. In most cases the binary search tree operations find, insert and delete have efficiency of <span style="font-family:Courier New;font-size:x-small;">O(log(d))</span> and the print/serialize operation is <span style="font-family:Courier New;font-size:x-small;">O(N*log(d))</span>, where <span style="font-family:Courier New;font-size:x-small;">d</span> is the maximum depth of the tree and <span style="font-family:Courier New;font-size:x-small;">N</span> is the total number of tree nodes.</p>
<p>Today, I will show a <strong><span style="font-family:Courier New;font-size:x-small;">set</span></strong> implemented using a binary search tree. This implementation choice means that the set datatype operations have the same efficiency as the corresponding binary search tree operations. This implementation choice also results in the constraint that the set of values for any kind of item, that we want to put in such set, must have total ordering. In other words, the standard (or user-defined) <span style="font-family:Courier New;font-size:x-small;"><strong>lt</strong> </span>operation must be applicable on any pair of items belonging to the set.</p>
<p>Here is the code:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">import module</span><span style="color:#000000;"> namespace set-impl </span><span style="color:#000096;">=</span><span style="color:#640064;">&#8220;http://fxsl.sf.net/data/set/implementation&#8221;</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">              at </span></span><span style="font-family:Times New Roman;color:#640064;">&#8220;implementations/set-implementation-as-binary-search-tree.xquery&#8221;</span><span style="font-family:Times New Roman;"><span style="color:#000000;">;<br />
              </span><br />
<span style="color:#006400;">declare namespace</span><span style="color:#000000;"> set </span><span style="color:#000096;">=</span><span style="color:#640064;"><a href="http://fxsl.sf.net/data/set">http://fxsl.sf.net/data/set</a></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="color:#640064;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  Create an empty set &#8212; </span><span style="font-family:Cambria Math;">∅</span><span style="font-family:Times New Roman;"> (0&#215;2205)</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> :)</span></span><br />
<span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set:set</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><strong><span style="font-family:Times New Roman;color:#fa6400;">set-impl:set</span></strong><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
};</span></span></p>
<p><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as xs:boolean<br />
{<br />
   </span><strong><span style="color:#fa6400;">set-impl:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as xs:integer<br />
{<br />
   </span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set:equals</span></strong><br />
            (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">            )<br />
         as xs:boolean<br />
{<br />
    </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:equals</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set:add</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
     )<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:add</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pItem)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></p>
<p><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The Set Theory belongs to (member of) </span><span style="font-family:Cambria Math;">∈</span><span style="font-family:Times New Roman;">  (0x22F2)</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  operation</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> :)</span></span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set:member</span></strong><br />
</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">      )<br />
         as xs:boolean<br />
{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:member</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span></p>
<p><strong><span style="color:#339966;">(:</span></strong><br />
 <span style="color:#008c00;"><span style="font-family:Times New Roman;">The Set Theory does not belong to (not member of)</span><span style="font-family:Cambria Math;">∉</span><span style="font-family:Times New Roman;">  (0&#215;2209)</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  operation</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> <strong><span style="color:#339966;">:)</span></strong></span></span></p>
<p><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> set:not-member<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">      )<br />
         as xs:boolean<br />
{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet))<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;">set:remove<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
     )<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:remove</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span><span style="color:#000000;">], </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pItem)<br />
};</span></span></p>
<p><strong><span style="font-family:Times New Roman;"><span style="color:#339966;">(:</span><br />
</span></strong><span style="color:#008c00;"><span style="font-family:Times New Roman;">  The classic set-theory U operation &#8212; union of two sets</span></span><br />
<strong><span style="font-family:Times New Roman;color:#008c00;">:)</span></strong><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> set:U<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)<br />
};</span></span></p>
<p><span style="color:#008c00;"><span style="font-family:Times New Roman;"><strong><span style="color:#339966;">(:<br />
</span></strong>  The classic set-theory set-difference operation \</span></span><br />
<strong><span style="font-family:Times New Roman;color:#008c00;">:)</span></strong><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> set:diff<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)<br />
};</span></span></p>
<p><span style="color:#008c00;"><span style="font-family:Times New Roman;"><strong><span style="color:#339966;">(:</span></strong> <br />
</span></span><span style="color:#008c00;"><span style="font-family:Times New Roman;">The classic set-theory ∩  (∩) /\</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  set-intersection operation</span></span><br />
<strong><span style="font-family:Times New Roman;color:#008c00;">:)</span></strong><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> set:intersect<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:intersect</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)<br />
};</span></span><strong><span style="color:#339966;">(:<br />
</span></strong><span style="color:#008c00;"><span style="font-family:Times New Roman;">The classic set-theory symmetric-difference operation </span></span><br />
<strong><span style="font-family:Times New Roman;color:#008c00;">:)</span></strong><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> set:sym-diff<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:sym-diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)<br />
};<br />
</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"><strong><span style="color:#339966;">(:</span></strong> <br />
</span></span><span style="color:#008c00;"><span style="font-family:Times New Roman;">The classic set-theory set </span><span style="font-family:Cambria Math;">⊇</span><span style="font-family:Times New Roman;"> (&#8216;⊇&#8217;) operation</span></span><br />
<strong><span style="font-family:Times New Roman;color:#008c00;">:)</span></strong><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> set:includes<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as xs:boolean<br />
{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:includes</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;">set:print<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:print</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;">set:serialize<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:serialize</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;">set:deserialize<br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSerialization as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:deserialize</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSerialization)<br />
};</span></td>
</tr>
</tbody>
</table>
<p>Now, you would be right that this code shows very little, if anything, at all. However, it has at least two virtues:</p>
<ul>
<li>Can serve as interface.</li>
<li>Is implementation independent – to use a different implementation just import another implementation module and bind the prefix <span style="font-family:Courier New;font-size:x-small;">set-impl</span> to its namespace.</li>
</ul>
<p>Having said that, here is the “true” implementation, which is contained in the file “<span style="font-family:Consolas;">implementations/set-implementation-as-binary-search-tree.xquery</span>”.</p>
<p>This is a separate XQuery module with its own namespace. It imports and uses the module that implements the binary search tree:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">module</span><span style="color:#000000;"> namespace set-impl </span><span style="color:#000096;">=</span><span style="color:#640064;">&#8220;http://fxsl.sf.net/data/set/implementation&#8221;</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">              at </span></span><span style="font-family:Times New Roman;"><span style="color:#640064;">&#8220;../../BinaryTree/bintreeModule.xquery&#8221;</span><span style="color:#000000;">;</span></span></p>
<p><span style="color:#006400;">import module</span><span style="color:#000000;"> namespace tree </span><span style="color:#000096;">=</span><span style="color:#640064;"><a href="http://fxsl.sf.net/data/bintree">http://fxsl.sf.net/data/bintree</a>;</span></td>
</tr>
</tbody>
</table>
<p>The set implementation module “contains” a binary search tree. The “empty set” <span style="color:#008c00;"><span style="font-family:Cambria Math;">∅ </span></span>is nothing else than a zero-argument function that returns an empty tree:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  Create an empty set &#8212; </span><span style="font-family:Cambria Math;">∅</span><span style="font-family:Times New Roman;"> (0&#215;2205)</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> :)</span></span><br />
<span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set-impl:set</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:tree</span></strong><span style="color:#000000;">()}</span><span style="color:#008c00;">   (: underlying bintree :)</span></span><br />
<span style="font-family:Times New Roman;color:#000000;">};</span></p>
</td>
</tr>
</tbody>
</table>
<p>Many of the basic set operations have their binary search tree counterparts. Here is what it means in our implementation for a set to be “empty” and how we compute the size of a set:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set-impl:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as xs:boolean<br />
{<br />
   </span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span></span><span style="color:#000000;">]())<br />
};</span></p>
<p> </p>
<p><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as xs:integer<br />
{<br />
   </span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;color:#000000;">]())<br />
};</span></td>
</tr>
</tbody>
</table>
<p>Two sets are equal exactly when they have the same size and the sequences of their atomized values are deep-equal:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set-impl:equals</span></strong><br />
            (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">            )<br />
         as xs:boolean<br />
{<br />
    </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1) </span><span style="color:#000096;">eq</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet1)<br />
   </span><span style="color:#000096;">and</span></span><br />
<span style="font-family:Times New Roman;color:#000000;">    </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">deep-equal</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1), </span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSet2))<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>Here is how we add an item to a set:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set-impl:add</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
     )<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span><span style="color:#000000;">](), </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pItem)}<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>and how we atomize a set:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;color:#000000;">]())<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>When is an item member of a set:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The Set Theory belongs to (member of) </span><span style="font-family:Cambria Math;">∈</span><span style="font-family:Times New Roman;">  (0x22F2)</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  operation</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> :)</span></span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:member</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">      )<br />
         as xs:boolean<br />
{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:contains</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span><span style="color:#000000;">](), </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pItem)<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>and when it isn’t a member of a set:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The Set Theory does not belong to (not member of) </span><span style="font-family:Cambria Math;">∉</span><span style="font-family:Times New Roman;">  (0&#215;2209)</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  operation</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> :)</span></span></p>
<p><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:not-member</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">      )<br />
         as xs:boolean<br />
{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:member</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSet))<br />
};</span></td>
</tr>
</tbody>
</table>
<p>This is how we remove an item from a set:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:remove</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
     )<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span><span style="color:#000000;">](), </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pItem)}<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>The classic set theory U (union) operation returns the union of two sets. Making use of the new standard XPath 3.0 higher order function<span style="font-family:Courier New;font-size:small;"> <a href="http://www.w3.org/TR/xpath-functions-30/#func-fold-left" target="_blank"><strong>fold-left()</strong></a></span>, we add all items from the smaller of the two sets to the bigger, thus performing only the minimal possible number of add operations:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The classic set-theory U operation &#8212; union of two sets</span></span><br />
<span style="font-family:Times New Roman;color:#008c00;">:)</span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:U</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000096;">$</span><span style="color:#000000;">vBiggerSet </span><span style="color:#000096;">:=</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;"><br />
           </span><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1) </span><span style="color:#000096;">ge</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2))<br />
             </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet1<br />
             </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2,<br />
       </span><span style="color:#000096;">$</span><span style="color:#000000;">vSmallerSet </span><span style="color:#000096;">:=</span></span><br />
<span style="font-family:Times New Roman;color:#000000;">           </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1) </span><span style="color:#000096;">ge</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)))<br />
             </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet1<br />
             </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2<br />
    </span><strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">       </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">fold-left</span></strong><span style="color:#000000;">(set-impl:add#2, </span><span style="color:#000096;">$</span><span style="color:#000000;">vBiggerSet, </span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">vSmallerSet))<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>Similarly, the classic set theory \ (set difference) operation:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The classic set-theory set-difference operation \</span></span><br />
<span style="font-family:Times New Roman;color:#008c00;">:)</span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:diff</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">fold-left</span></strong><span style="color:#000000;">(set-impl:remove#2, </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSet2))<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>And the classic set theory <span style="color:#008c00;"><span style="font-family:Times New Roman;color:#000000;font-size:small;"><strong>∩</strong></span> </span>intersect operation:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The classic set-theory ∩  (∩) /\</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  set-intersection operation</span></span><br />
<span style="font-family:Times New Roman;color:#008c00;">:)</span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:intersect</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
   </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000096;">$</span><span style="color:#000000;">vBiggerSet </span><span style="color:#000096;">:=</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;"><br />
           </span><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1) </span><span style="color:#000096;">ge</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2))<br />
             </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet1<br />
             </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2,<br />
       </span><span style="color:#000096;">$</span><span style="color:#000000;">vSmallerSet </span><span style="color:#000096;">:=</span></span><br />
<span style="font-family:Times New Roman;color:#000000;">           </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1) </span><span style="color:#000096;">ge</span><strong><span style="color:#fa6400;">set-impl:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2)))<br />
             </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet1<br />
             </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet2,<br />
       </span><span style="color:#000096;">$</span><span style="color:#000000;">to-be-removed </span><span style="color:#000096;">:=</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;"><br />
           </span><strong><span style="color:#fa6400;">filter</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:not-member</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">?</span><span style="color:#000000;">, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">vBiggerSet),<br />
                      </span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">vSmallerSet)<br />
                     )<br />
    </span><strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">       </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">fold-left</span></strong><span style="color:#000000;">(set-impl:remove#2, </span><span style="color:#000096;">$</span><span style="color:#000000;">vSmallerSet, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">to-be-removed)<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>Two more set theory operations – symmetric difference:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The classic set-theory symmetric-difference operation </span></span><br />
<span style="font-family:Times New Roman;color:#008c00;">:)</span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:sym-diff</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:U</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1, </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2), </span><strong><span style="color:#fa6400;">set-impl:diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSet1))<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>and <span style="font-family:Cambria Math;color:#000000;font-size:small;"><strong>⊇</strong></span> (non-strict) set inclusion:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(:</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  The classic set-theory set </span><span style="font-family:Cambria Math;">⊇</span><span style="font-family:Times New Roman;"> (&#8216;⊇&#8217;) operation</span></span><br />
<span style="font-family:Times New Roman;color:#008c00;">:)</span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:includes</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet1 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
      </span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2 as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">     )<br />
         as xs:boolean<br />
{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set-impl:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet2)[</span><strong><span style="color:#fa6400;">set-impl:not-member</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">.</span><span style="color:#000000;">,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSet1)])<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>And finally, three infrastructural operations: <span style="font-family:Courier New;font-size:x-small;">print()</span>, <span style="font-family:Courier New;font-size:x-small;">serialize()</span> and <span style="font-family:Courier New;font-size:x-small;">deserialize()</span> :</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#e3f2f9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> <strong><span style="color:#ff6600;">set-impl:print</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet[</span><span style="color:#646464;">1</span></span><span style="color:#000000;">]())<br />
};</span> </p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set-impl:serialize</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSet as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">set-impl:print</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pSet)<br />
};</span></span></p>
<p><span style="color:#006400;">declare function </span><span style="font-family:Times New Roman;"><span style="color:#000000;"><strong><span style="color:#ff6600;">set-impl:deserialize</span></strong><br />
     (</span><span style="color:#000096;">$</span><span style="color:#000000;">pSerialization as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
  </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:deserialize</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">pSerialization)}<br />
};</span></td>
</tr>
</tbody>
</table>
<p>Here is a test of our set implementation:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#fde9d9;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000096;">$</span><span style="color:#000000;">set0 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong><span style="color:#000000;">(), </span><span style="color:#646464;">2</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">),<br />
     </span><span style="color:#000096;">$</span><span style="color:#000000;">set1 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong><span style="color:#000000;">(), </span><span style="color:#646464;">10</span><span style="color:#000000;">), </span><span style="color:#646464;">5</span><span style="color:#000000;">), </span><span style="color:#646464;">17</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">),<br />
     </span><span style="color:#000096;">$</span><span style="color:#000000;">set2 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:remove</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><span style="color:#646464;">5</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">),<br />
     </span><span style="color:#000096;">$</span><span style="color:#000000;">set3 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:remove</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><span style="color:#646464;">12</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">),<br />
     </span><span style="color:#000096;">$</span><span style="color:#000000;">set4 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong><span style="color:#000000;">(), </span><span style="color:#646464;">2</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">),<br />
     </span><span style="color:#000096;">$</span><span style="color:#000000;">set4 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong><span style="color:#000000;">(), </span><span style="color:#646464;">8</span><span style="color:#000000;">), </span><span style="color:#646464;">4</span><span style="color:#000000;">), </span><span style="color:#646464;">9</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">),<br />
     </span><span style="color:#000096;">$</span><span style="color:#000000;">set5 </span><span style="color:#000096;">:=</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:add</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong><span style="color:#000000;">(), </span><span style="color:#646464;">17</span><span style="color:#000000;">), </span><span style="color:#646464;">10</span><span style="color:#000000;">), </span><span style="color:#646464;">19</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
  </span><strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">    (<br />
            </span></span><span style="font-family:Times New Roman;color:#640064;">&#8216; set:empty(set:set()): &#8216;</span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:empty</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()),<br />
             </span><span style="color:#640064;">&#8216; set:size(set:set()): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:size</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:set</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()),<br />
             </span><span style="color:#640064;">&#8216; set:size($set0): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set0),<br />
             </span><span style="color:#640064;">&#8216; set:size($set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:data($set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:member(10,$set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">(</span><span style="color:#646464;">10</span><span style="color:#000000;">,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:member(17,$set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">(</span><span style="color:#646464;">17</span><span style="color:#000000;">,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:member(5,$set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">(</span><span style="color:#646464;">5</span><span style="color:#000000;">,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:member(2,$set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">(</span><span style="color:#646464;">2</span><span style="color:#000000;">,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:member(15,$set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">(</span><span style="color:#646464;">15</span><span style="color:#000000;">,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:data($set2): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2),<br />
             </span><span style="color:#640064;">&#8216; set:data($set3): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set3),<br />
             </span><span style="color:#640064;">&#8216; set:data($set4): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set4),<br />
             </span><span style="color:#640064;">&#8216; set:data(set:U($set1,$set4)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set4)),<br />
             </span><span style="color:#640064;">&#8216; set:print(set:U($set1,$set4)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set4)),<br />
             </span><span style="color:#640064;">&#8216; set:print(set:U($set4,$set1)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set4,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1)),<br />
             </span><span style="color:#640064;">&#8216; set:print(set:U($set1,$set2)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2)),<br />
             </span><span style="color:#640064;">&#8216; set:equals($set1, set:U($set1,$set2)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:equals</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2)),<br />
             </span><span style="color:#640064;">&#8216; set:data($set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:data($set4): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set4),<br />
             </span><span style="color:#640064;">&#8216; set:data(set:U($set1,$set4)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set4)),<br />
             </span><span style="color:#640064;">&#8216; set:print(set:U($set1,$set4)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:U</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set4)),<br />
             </span><span style="color:#640064;">&#8216; set:data($set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:data($set2): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2),<br />
             </span><span style="color:#640064;">&#8216; set:data(set:diff($set1,$set2)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2)),<br />
             </span><span style="color:#640064;">&#8216; set:print(tree:print(set:diff($set1,$set2)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1,</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2)),<br />
             </span><span style="color:#640064;">&#8216; set:data($set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:data($set2): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2),<br />
             </span><span style="color:#640064;">&#8216; set:data(set:intersect($set1, $set2)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:intersect</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2)),<br />
             </span><span style="color:#640064;">&#8216; set:data($set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:data($set5): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
             </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set5),<br />
             </span><span style="color:#640064;">&#8216; set:data(set:sym-diff($set1, $set5)): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:sym-diff</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set5)),<br />
             </span><span style="color:#640064;">&#8216; set:includes($set1, $set2): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:includes</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set2),<br />
             </span><span style="color:#640064;">&#8216; set:includes($set1, $set5): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:includes</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set5),<br />
             </span><span style="color:#640064;">&#8216; set:includes($set1, set:set()): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:includes</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">set1, </span><strong><span style="color:#fa6400;">set:set</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()),<br />
             </span><span style="color:#640064;">&#8216; set:member((), $set1): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">((), </span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set1),<br />
             </span><span style="color:#640064;">&#8216; set:member((), set:set()): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:member</span></strong><span style="color:#000000;">((), </span><strong><span style="color:#fa6400;">set:set</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()),<br />
             </span><span style="color:#640064;">&#8216; set:serialize($set5): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:serialize</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set5),<br />
             </span><span style="color:#640064;">&#8216; set:data(set:deserialize(set:serialize($set5))): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:deserialize</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:serialize</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">set5))),<br />
             </span><span style="color:#640064;">&#8216; set:size(set:deserialize(set:serialize($set5))): &#8216;</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">,<br />
   </span><strong><span style="color:#fa6400;">set:size</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:deserialize</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">set:serialize</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;color:#000000;">set5)))<br />
             )</span></p>
</td>
</tr>
</tbody>
</table>
<p>When this test is executed, the expected, correct results are produced:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#eaf1dd;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#000000;">set:empty(set:set()):  true<br />
set:size(set:set()):  0<br />
set:size($set0):  1<br />
set:size($set1):  3<br />
set:data($set1):  5 10 17<br />
set:member(10,$set1):  true<br />
set:member(17,$set1):  true<br />
set:member(5,$set1):  true<br />
set:member(2,$set1):  false<br />
set:member(15,$set1):  false<br />
set:data($set2):  10 17<br />
set:data($set3):  5 10 17<br />
set:data($set4):  4 8 9<br />
set:data(set:U($set1,$set4)):  4 5 8 9 10 17<br />
set:print(set:U($set1,$set4)): </span><br />
<strong><span style="color:#993300;">&lt;treeNode&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">10</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">5</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">4</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">8</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">            </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">9</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">17</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;"><span style="color:#000000;">set:print(set:U($set4,$set1)): </span><br />
</span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">8</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">4</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">5</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">      </span></span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">9</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">10</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">            </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">17</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;"><span style="color:#000000;">set:print(set:U($set1,$set2)): </span><br />
</span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">10</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">5</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">17</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;"><span style="color:#000000;">set:equals($set1, set:U($set1,$set2)):  true<br />
set:data($set1):  5 10 17<br />
set:data($set4):  4 8 9<br />
set:data(set:U($set1,$set4)):  4 5 8 9 10 17<br />
set:print(set:U($set1,$set4)): </span><br />
</span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">10</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">5</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">4</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">         </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">8</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">            </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">9</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">         </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">17</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;"><span style="color:#000000;">set:data($set1):  5 10 17<br />
set:data($set2):  10 17<br />
set:data(set:diff($set1,$set2)):  5<br />
set:print(tree:print(set:diff($set1,$set2)): </span><br />
</span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">5</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">set:data($set1):  5 10 17<br />
set:data($set2):  10 17<br />
set:data(set:intersect($set1, $set2)):  10 17<br />
set:data($set1):  5 10 17<br />
set:data($set5):  10 17 19<br />
set:data(set:sym-diff($set1, $set5)):  5 19<br />
set:includes($set1, $set2):  true<br />
set:includes($set1, $set5):  false<br />
set:includes($set1, set:set()):  true<br />
set:member((), $set1):  true<br />
set:member((), set:set()):  true<br />
set:serialize($set5): </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">17</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">10</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">      </span><span style="font-family:Times New Roman;"><strong><span style="color:#993300;">&lt;value&gt;</span></strong><span style="color:#000000;">19</span><strong><span style="color:#993300;">&lt;/value&gt;</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<strong><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span></strong><br />
<span style="font-family:Times New Roman;color:#000000;">set:data(set:deserialize(set:serialize($set5))): 10 17 19<br />
set:size(set:deserialize(set:serialize($set5))):  3</span></p>
</td>
</tr>
</tbody>
</table>
<p>In a few of my next posts I will show other interesting applications of the two new datatypes: the set and the binary search tree.</p>
<p>Useful utility: <a href="http://www.zip-code-database.org">Zip Codes</a> &#8211; Free zip code lookup and zip code database download.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=84&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2012/01/12/the-set-datatype-implemented-in-xpath-3-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>
	</item>
		<item>
		<title>Part 2: The Binary Search Data Structure with XPath 3.0, Deleting a node</title>
		<link>http://dnovatchev.wordpress.com/2012/01/11/part-2-the-binary-search-data-structure-with-xpath-3-0-deleting-a-node/</link>
		<comments>http://dnovatchev.wordpress.com/2012/01/11/part-2-the-binary-search-data-structure-with-xpath-3-0-deleting-a-node/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 10:30:20 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[functional data structures]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[XPath 3.0]]></category>

		<guid isPermaLink="false">https://dnovatchev.wordpress.com/?p=66</guid>
		<description><![CDATA[In the first part of this post I presented a Binary Search Tree implemented in pure XPath 3.0. Some new nice features of XPath 3.0 were shown in action and other, still missing but very important features were identified and &#8230; <a href="http://dnovatchev.wordpress.com/2012/01/11/part-2-the-binary-search-data-structure-with-xpath-3-0-deleting-a-node/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=66&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://dnovatchev.wordpress.com/2011/02/08/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/" target="_blank">the first part</a> of this post I presented a Binary Search Tree implemented in pure XPath 3.0. Some new nice features of XPath 3.0 were shown in action and other, still missing but very important features were identified and discussed.</p>
<p>The only operation that was missing was the deletion of a node from the tree. I show how to do this now.</p>
<p>This is the function that consumers will use:</p>
<table style="width:auto;border-collapse:collapse;background:#d7f2f5;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:times new roman;color:#008c00;">(:</span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">Delete from $pTree the node containing $pItem.</span></span><br /><span style="font-family:times new roman;color:#008c00;">:)</span></p>
<p><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:deleteNode<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree, </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem, </span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;color:#000000;">)<br />};</span></p>
</td>
</tr>
</tbody>
</table>
<p>It simply delegates to a similar internal function that also requires a third argument – the depth of the (sub)tree on which the delete is performed. Why is the depth necessary? The answer will come later.</p>
<table style="width:auto;border-collapse:collapse;background:#d7f2f5;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:times new roman;color:#008c00;">(:</span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">Delete from $pTree the node containing $pItem.</span></span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">$pTree has a depth of $pDepth (1 if not a subtree)</span></span><br /><span style="font-family:times new roman;color:#008c00;">:)</span></p>
<p><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:deleteNode<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:times new roman;"><span style="color:#000000;">(),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pDepth as xs:integer<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br /></span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">top&nbsp;&nbsp; </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">left&nbsp; </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">right </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem </span><span style="color:#000096;">eq</span><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">top)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:deleteTopNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree, </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pDepth)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem </span><span style="color:#000096;">lt</span><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">top)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pItem,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pItem,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />};</span></p>
</td>
</tr>
</tbody>
</table>
<p>We see that the<span style="font-family:courier new;"> deleteNode()</span> function simply dispatches the operation to the left or right subtree and calls another function – <span style="font-family:courier new;">deleteTopNode()</span> – whenever the item to be deleted happens to be the value of the top node.</p>
<table style="width:auto;border-collapse:collapse;background:#d7f2f5;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<table style="width:auto;border-collapse:collapse;background:#daeef3;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:deleteTopNode<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pDepth as xs:integer<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">left </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">right </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)<br />&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">left) </span><span style="color:#000096;">and</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:tree</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">left) </span><span style="color:#000096;">and</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right)))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">right) </span><span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">left)) </span><span style="color:#000096;">and</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">left)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">left)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">left)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">left) </span><span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#008c00;">&nbsp; (: both subtrees are non-empty :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth </span><span style="color:#000096;">mod</span><span style="color:#000000;"> </span><span style="color:#646464;">2</span><span style="color:#000000;"> </span><span style="color:#000096;">eq</span><span style="color:#000000;"> </span><span style="color:#646464;">0</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">subtree </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">vItem </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:leftmost</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">subtree)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">newSubtree </span><span style="color:#000096;">:=</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">subtree, </span><span style="color:#000096;">$</span><span style="color:#000000;">vItem, </span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">vItem},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">left},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">newSubtree},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree) </span><span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">subtree </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">vItem </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:rightmost</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">subtree)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">newSubtree</span><span style="color:#000096;">:=</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">subtree, </span><span style="color:#000096;">$</span><span style="color:#000000;">vItem, </span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">vItem},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">newSubtree},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree) </span><span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;color:#000000;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />};</span></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family:courier new;">deleteTopNode()</span> does the real deletion work. The operation is straightforward in the case when the tree is empty or either the left subtree or the right subtree is empty.</p>
<p>It becomes interesting when both subtrees are non-empty. In order to understand what the last 20 lines of this code mean, it is best to read <a href="http://www.tech-faq.com/binary-tree-deleting-a-node.html" target="_blank">a good source on the binary search tree delete operation</a>.</p>
<p>In a few words:</p>
<ul>
<li>If the depth is even, then we move to the top the leftmost node (without its right subtree) of the right subtree.
<li>If the depth is odd, then we move to the top the rightmost node (without its left subtree) of the left subtree. </li>
</ul>
<p>Why is this different processing done, depending on the oddness of the depth of the subtree? If we always used the leftmost node of the right subtree, then a series of deletions would create a severely imbalanced (to the right) tree. Imbalanced trees lose the advantages of the binary search tree with search and insertions becoming of linear complexity (instead of O(log(N))&nbsp; ) and sorting becoming O(N^2) instead of O(N*log(N)).</p>
<p>Thus, in order to avoid this deteriorating effect, we need to use with a pseudo-random frequency both the left and the right subtrees. In most cases this can be achieved simply by using the oddness of the depth of the tree, whose top node is to be replaced.</p>
<p>Below is the complete code of the Binary Search tree. Do note that I have added a new “property” to the tree datatype – “size”. Also, note the functions <span style="font-family:courier new;">tree:leftmost()</span> and <span style="font-family:courier new;">tree:rightmost()</span> – used by <span style="font-family:courier new;">tree:deleteTopNode()</span></p>
<p><span style="font-family:courier new;"><span style="font-family:georgia;">Another change is that now the second argument of <span style="font-family:courier new;">tree:contains()</span>&nbsp;&nbsp; is of type&nbsp; <span style="font-family:courier new;">item()?</span>&nbsp;&nbsp; &#8212; that is, it can be empty. By definition, any tree contains the &#8220;empty item&#8221;.</span></span></p>
<p><span style="font-family:courier new;"><span style="font-family:georgia;">Finally, there is a new pair of functions: <span style="font-family:courier new;">tree:serialize()</span> and&nbsp;&nbsp; <span style="font-family:courier new;">tree:deserialize()</span>  . The former is a synonym of&nbsp; <span style="font-family:courier new;">tree:print()</span> and the latter loads the XML representation created by&nbsp; <span style="font-family:courier new;">tree:serialize()</span> into a tree.</span></span></p>
<table style="width:auto;border-collapse:collapse;background:#d7f2f5;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<table style="width:auto;border-collapse:collapse;background:#daeef3;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:times new roman;"><span style="color:#006400;">module</span><span style="color:#000000;"> namespace tree </span><span style="color:#000096;">=</span><span style="color:#000000;"> </span><span style="color:#640064;">&#8220;http://fxsl.sf.net/data/bintree&#8221;</span></span><span style="font-family:times new roman;"><span style="color:#000000;">;</span></span></p>
<div><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:top<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br /></span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;"> ()<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]()<br />};</span></span></span></div>
<div><span style="font-family:times new roman;">&nbsp;</span></div>
<div><span style="font-family:times new roman;">&nbsp;</span></div>
<p><span style="font-family:times new roman;">&nbsp;</span> <span style="font-family:times new roman;"></p>
<div><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:left<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br /></span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">2</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]))<br /></span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:tree</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br /></span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">2</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]()</span></span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;">&nbsp;</span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#000000;">&nbsp;</span></span></span></span>&nbsp;</div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;">&nbsp;</span></span></div>
<p><span style="font-family:times new roman;"><span style="font-family:times new roman;">&nbsp;</span></span> <span style="font-family:times new roman;"><span style="font-family:times new roman;"></p>
<div><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:right<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br /></span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">3</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]))<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:tree</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">3</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]()<br />};</span></span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#006400;">&nbsp;</span></span></span>&nbsp;</div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:size<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as xs:integer<br />{<br /></span><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">4</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]))<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><span style="color:#646464;">0</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp; </span><strong><span style="font-family:times new roman;color:#0000fa;">else</span></strong><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">4</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]()<br />};</span></span></span></span><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#006400;">&nbsp;</span></span></span>&nbsp;</div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:tree</span></strong><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">+</span></span></span></span><span style="font-family:times new roman;"><span style="font-family:times new roman;color:#000000;">{</span></span><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#000000;">};</span></span></span> </div>
<div><span style="font-family:times new roman;color:#000000;">&nbsp;</span><span style="font-family:times new roman;color:#000000;">&nbsp; (</span></div>
<div><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp; <span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {()},</span><span style="color:#008c00;">&nbsp;&nbsp; (: top() :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {()},</span><span style="color:#008c00;">&nbsp;&nbsp; (: left() :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {()},</span><span style="color:#008c00;">&nbsp;&nbsp; (: right() :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#646464;">0</span><span style="color:#000000;">}</span><span style="color:#008c00;">&nbsp;&nbsp;&nbsp;&nbsp; (: size() :)</span></span></span></div>
<div><span style="font-family:times new roman;color:#000000;"><span style="font-family:times new roman;"><span style="color:#008c00;">&nbsp;</span></span></span><span style="font-family:times new roman;"><span style="color:#000000;">&nbsp; )<br />};</span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:empty<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as xs:boolean<br />{<br /></span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree) </span><span style="color:#000096;">or</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">]())<br />};</span></span></span></div>
<p><span style="font-family:times new roman;">&nbsp;</span><span style="font-family:times new roman;"><span style="line-height:115%;font-family:'Times New Roman',serif;color:darkgreen;font-size:12pt;">declare function</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> tree:contains<br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pTree </span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">as</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> (</span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">function</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">() as </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#646464;font-size:12pt;">item</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">()</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">*</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">)</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">*</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">,<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem as </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#646464;font-size:12pt;">item</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">()</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">?</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br /></span><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>as xs:boolean<br />{<br /></span><span style="font-family:times new roman;color:#000000;">&nbsp;</span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">if</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">empty</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem))<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">then</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">true</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">()<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">else</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">if</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">tree:empty</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pTree))<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">then</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">false</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">()<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">else</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">let</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">top </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">:=</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">tree:top</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pTree)<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#0000fa;font-size:12pt;">return</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">eq</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">top)<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">or</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">lt</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">top<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">and</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">tree:contains</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">tree:left</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pTree),</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem)<br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br /></span><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">or</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">gt</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"> </span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">top<br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">and</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;"><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">tree:contains</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:#fa6400;font-size:12pt;">tree:right</span></strong><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">(</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pTree),</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:#000096;font-size:12pt;">$</span><span style="line-height:115%;font-family:'Times New Roman',serif;color:black;font-size:12pt;">pItem)<br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br />};</span></span></span></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#008c00;">(:</span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">Delete from $pTree the node containing $pItem.</span></span><br /><span style="font-family:times new roman;color:#008c00;">:)</span></span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:deleteNode<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree, </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem, </span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />};</span></span></span></div>
<div>
<div>
<div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:deleteNode<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:times new roman;"><span style="color:#000000;">(),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pDepth as xs:integer<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br /></span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">top&nbsp;&nbsp; </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">left&nbsp; </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">right </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem </span><span style="color:#000096;">eq</span><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">top)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:deleteTopNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree, </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pDepth)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem </span><span style="color:#000096;">lt</span><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">top)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pItem,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pItem,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pDepth</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />};</span></span></span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#000000;"></span></span></span></span>&nbsp;</div>
<p><span style="line-height:14pt;"><font color="#006400">declare function</font></span><span style="line-height:14pt;"><font color="#000000"> tree:deleteTopNode<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree </font></span><b><span style="line-height:14pt;"><font color="#fa6400">as</font></span></b><span style="line-height:14pt;"><font color="#000000"> (</font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() as </font></span><span style="line-height:14pt;"><font color="#646464">item</font></span><span style="line-height:14pt;"><font color="#000000">()</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><font color="#000000">)</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><font color="#000000">,<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pDepth as xs:integer<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">as</font></span></b><span style="line-height:14pt;"><font color="#000000"> (</font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() as </font></span><span style="line-height:14pt;"><font color="#646464">item</font></span><span style="line-height:14pt;"><font color="#000000">()</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><font color="#000000">)</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><br /><font color="#000000">{<br /><span>&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">let</font></span></b><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:left</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree),<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:right</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree)<br /><span>&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">return</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">if</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left) </font></span><span style="line-height:14pt;"><font color="#000096">and</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right))<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">then</font></span></b><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:tree</font></span></b><span style="line-height:14pt;"><font color="#000000">()<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">else</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">if</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left) </font></span><span style="line-height:14pt;"><font color="#000096">and</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">not</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right)))<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">then</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">else</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">if</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">not</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left)) </font></span><span style="line-height:14pt;"><font color="#000096">and</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right))<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">then</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">else</font></span></b><span style="line-height:14pt;"><font color="#008c00"><span>&nbsp; </span>(: both subtrees are non-empty :)</font></span><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">if</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pDepth </font></span><span style="line-height:14pt;"><font color="#000096">mod</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#646464">2</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#000096">eq</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#646464">0</font></span><span style="line-height:14pt;"><font color="#000000">)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">then</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">let</font></span></b><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">subtree </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:right</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree),<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">vItem </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:top</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:leftmost</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">subtree)),<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">newSubtree </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:deleteNode</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">subtree, </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">vItem, </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pDepth</font></span><span style="line-height:14pt;"><font color="#000096">+</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">return</font></span></b><span style="line-height:14pt;"><br /><font color="#000000"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">vItem},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">newSubtree},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:size</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree) </font></span><span style="line-height:14pt;"><font color="#000096">-</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">}<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">else</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">let</font></span></b><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">subtree </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:left</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree),<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">vItem </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:top</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:rightmost</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">subtree)),<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">newSubtree</font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:deleteNode</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">subtree, </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">vItem, </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pDepth</font></span><span style="line-height:14pt;"><font color="#000096">+</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">return</font></span></b><span style="line-height:14pt;"><br /><font color="#000000"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">vItem},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">newSubtree},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:size</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree) </font></span><span style="line-height:14pt;"><font color="#000096">-</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">}<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br />};</font></span>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#000000;"></span></span></span></span>&nbsp;</div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#008c00;">(:</span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">&nbsp; Find/Return the leftmost node of the</span></span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">&nbsp; non-empty tree $pTree</span></span><br /><span style="font-family:times new roman;color:#008c00;">:)</span></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:leftmost<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">+</span></span><span style="font-family:times new roman;"><span style="color:#000000;"> )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">left </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)<br />&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">left))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:leftmost</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">left)<br />};</span></span></span></div>
<div><span style="font-family:times new roman;">&nbsp;</span></div>
<p><span style="font-family:times new roman;">&nbsp;</span> <span style="font-family:times new roman;"></p>
<div><span style="font-family:times new roman;">&nbsp;</span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:rightmost<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">+</span></span><span style="font-family:times new roman;"><span style="color:#000000;"> )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">right </span><span style="color:#000096;">:=</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)<br />&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:rightmost</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">right)<br />};</span></span></span></div>
<div><span style="font-family:times new roman;">&nbsp;</span><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:insert<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">pItem as </span><span style="color:#646464;">item</span></span><span style="font-family:times new roman;"><span style="color:#000000;">()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">+</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem},</span><span style="color:#008c00;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (: top()&nbsp;&nbsp; :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:tree</span></strong><span style="color:#000000;">()},</span><span style="color:#008c00;"> (: left()&nbsp; :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:tree</span></strong><span style="color:#000000;">()},</span><span style="color:#008c00;"> (: right() :)</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><span style="color:#646464;">1</span><span style="color:#000000;">}</span><span style="color:#008c00;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (: size()&nbsp; :)</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="font-family:times new roman;color:#0000fa;">else</span></strong><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem </span><span style="color:#000096;">lt</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree), </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pItem)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree)</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pItem </span><span style="color:#000096;">gt</span><span style="color:#000000;"> </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree), </span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pItem)},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {</span><strong><span style="color:#fa6400;">tree:size</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree)</span><span style="color:#000096;">+</span><span style="color:#646464;">1</span></span><span style="font-family:times new roman;"><span style="color:#000000;">}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;color:#000096;">$</span><span style="font-family:times new roman;"><span style="color:#000000;">pTree<br />};</span></span></span></div>
<p><span style="font-family:times new roman;"></p>
<div><span style="font-family:times new roman;"><span style="color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:print<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as </span><span style="color:#646464;">element</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br />&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)))<br />&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="color:#000096;">&lt;</span><span style="color:#000000;">treeNode</span><span style="color:#000096;">&gt;</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="color:#000096;">&lt;</span><span style="color:#000000;">value</span><span style="color:#000096;">&gt;</span><span style="color:#000000;">{</span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree)}</span><span style="color:#000096;">&lt;/</span><span style="color:#000000;">value</span><span style="color:#000096;">&gt;</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">&lt;/</span><span style="color:#000000;">treeNode</span><span style="color:#000096;">&gt;</span></span><br /><span style="font-family:times new roman;color:#000000;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-family:times new roman;color:#0000fa;">else </span></strong><span style="font-family:times new roman;"><span style="color:#000000;">()<br />};</span></span></span></div>
<div><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#000000;">&nbsp;</span></span></span></span></span></span></span></span>&nbsp;</div>
<p style="line-height:13pt;margin:0 0 10pt;" class="MsoNormal"><span style="line-height:14pt;"><font color="#006400">declare function</font></span><span style="line-height:14pt;"><font color="#000000"> tree:serialize<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree </font></span><b><span style="line-height:14pt;"><font color="#fa6400">as</font></span></b><span style="line-height:14pt;"><font color="#000000"> (</font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() as </font></span><span style="line-height:14pt;"><font color="#646464">item</font></span><span style="line-height:14pt;"><font color="#000000">()</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><font color="#000000">)</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><font color="#000000">)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>as </font></span><span style="line-height:14pt;"><font color="#646464">element</font></span><span style="line-height:14pt;"><font color="#000000">()</font></span><span style="line-height:14pt;"><font color="#000096">?</font></span><span style="line-height:14pt;"><br /><font color="#000000">{<br /><span>&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:print</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pTree)<br />};</font></p>
<p></span><span style="line-height:14pt;"><font color="#006400">declare function</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:deserialize</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pXml as </font></span><span style="line-height:14pt;"><font color="#646464">element</font></span><span style="line-height:14pt;"><font color="#000000">()</font></span><span style="line-height:14pt;"><font color="#000096">?</font></span><span style="line-height:14pt;"><font color="#000000">)<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">as</font></span></b><span style="line-height:14pt;"><font color="#000000"> (</font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() as </font></span><span style="line-height:14pt;"><font color="#646464">item</font></span><span style="line-height:14pt;"><font color="#000000">()</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><font color="#000000">)</font></span><span style="line-height:14pt;"><font color="#000096">*</font></span><span style="line-height:14pt;"><br /><font color="#000000">{<br /><span>&nbsp;</span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">if</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><b><span style="line-height:14pt;"><font color="#fa6400">empty</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pXml))<br /><span>&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">then</font></span></b><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:tree</font></span></b><span style="line-height:14pt;"><font color="#000000">()<br /><span>&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">else</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000">&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#0000fa">let</font></span></b><span style="line-height:14pt;"><font color="#000000"> </font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:deserialize</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pXml</font></span><span style="line-height:14pt;"><font color="#000096">/</font></span><span style="line-height:14pt;"><font color="#000000">treeNode[</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">]),<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right </font></span><span style="line-height:14pt;"><font color="#000096">:=</font></span><span style="line-height:14pt;"><font color="#000000"> </font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:deserialize</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pXml</font></span><span style="line-height:14pt;"><font color="#000096">/</font></span><span style="line-height:14pt;"><font color="#000000">treeNode[</font></span><span style="line-height:14pt;"><font color="#646464">2</font></span><span style="line-height:14pt;"><font color="#000000">])<br /><span>&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#0000fa">return</font></span></b><span style="line-height:14pt;"><br /><font color="#000000"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>(<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">pXml</font></span><span style="line-height:14pt;"><font color="#000096">/</font></span><span style="line-height:14pt;"><font color="#000000">value</font></span><span style="line-height:14pt;"><font color="#000096">/</font></span><span style="line-height:14pt;"><font color="#646464">node</font></span><span style="line-height:14pt;"><font color="#000000">()[</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">]},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right},<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span><b><span style="line-height:14pt;"><font color="#fa6400">function</font></span></b><span style="line-height:14pt;"><font color="#000000">() {</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:size</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">left)</font></span><span style="line-height:14pt;"><font color="#000096">+</font></span><b><span style="line-height:14pt;"><font color="#fa6400">tree:size</font></span></b><span style="line-height:14pt;"><font color="#000000">(</font></span><span style="line-height:14pt;"><font color="#000096">$</font></span><span style="line-height:14pt;"><font color="#000000">right)</font></span><span style="line-height:14pt;"><font color="#000096">+</font></span><span style="line-height:14pt;"><font color="#646464">1</font></span><span style="line-height:14pt;"><font color="#000000">}<br /><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>)<br />};</font></span></p>
<div>&nbsp;</div>
<p><span style="font-family:times new roman;"><span style="font-family:times new roman;"><span style="color:#008c00;">(: tree:data()</span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">&nbsp; Prints only the data &#8212; depth first.</span></span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">&nbsp;&nbsp; In effect this is sort() &#8212; quite good</span></span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">&nbsp;&nbsp; for random data.</span></span><br /><span style="color:#008c00;"><span style="font-family:times new roman;">:)</span></span><br /><span style="font-family:times new roman;color:#006400;">declare function</span><span style="font-family:times new roman;"><span style="color:#000000;"> tree:data<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:times new roman;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">{<br /></span></span><span style="font-family:times new roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">not</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)))<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">then</span></strong></span><br /><span style="color:#000000;"><span style="font-family:times new roman;">&nbsp;&nbsp;&nbsp; (<br />&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:times new roman;"><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:left</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree)),<br />&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:top</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree),<br />&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:right</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:times new roman;"><span style="color:#000000;">pTree))<br />&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">else</span></strong></span><span style="font-family:times new roman;color:#000000;">()<br />};</span></span></span></p>
<p></span></span></span></span></span></p>
</div>
</div>
</div>
<p></span></span></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Now, let’s test just the <span style="font-family:courier new;">deleteNode</span> operation:</p>
<table style="width:auto;border-collapse:collapse;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;background:#ebe5d1;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:times new roman;"><span style="font-size:x-small;"><strong><span style="color:#0000fa;">let</span></strong><span style="color:#000000;"> </span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree </span><span style="color:#000096;">:=</span></span></span><br /><span style="font-family:times new roman;color:#000000;font-size:x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="font-size:x-small;"><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:tree</span></strong><span style="color:#000000;">(),</span><span style="color:#646464;">10</span><span style="color:#000000;">),</span><span style="color:#646464;">5</span><span style="color:#000000;">),</span><span style="color:#646464;">17</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">),<br />&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree2 </span><span style="color:#000096;">:=</span></span></span><br /><span style="font-family:times new roman;color:#000000;font-size:x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="font-size:x-small;"><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree,</span><span style="color:#646464;">3</span><span style="color:#000000;">),</span><span style="color:#646464;">8</span><span style="color:#000000;">),</span><span style="color:#646464;">14</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">),<br />&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree3 </span><span style="color:#000096;">:=</span></span></span><br /><span style="font-family:times new roman;color:#000000;font-size:x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="font-size:x-small;"><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree2,</span><span style="color:#646464;">20</span><span style="color:#000000;">),</span><span style="color:#646464;">6</span><span style="color:#000000;">),</span><span style="color:#646464;">9</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">),<br />&nbsp;&nbsp;&nbsp; </span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4 </span><span style="color:#000096;">:=</span></span></span><br /><span style="font-family:times new roman;color:#000000;font-size:x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:times new roman;"><span style="font-size:x-small;"><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:insert</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree3,</span><span style="color:#646464;">12</span><span style="color:#000000;">),</span><span style="color:#646464;">15</span><span style="color:#000000;">),</span><span style="color:#646464;">7</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)<br />&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#0000fa;">return</span></strong></span></span><br /><span style="color:#000000;"><span style="font-family:times new roman;"><span style="font-size:x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span></span></span><span style="font-family:times new roman;color:#640064;font-size:x-small;">&#8216; tree:print($vBigTree4): &#8216;</span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">vBigTree4),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:data($vBigTree4): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">vBigTree4),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; ====================================&#8217;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:print(tree:deleteNode($vBigTree4, 7)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">7</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:data(tree:deleteNode($vBigTree4, 7)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">7</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; ====================================&#8217;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:print(tree:deleteNode($vBigTree4, 12)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">12</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:data(tree:deleteNode($vBigTree4, 12)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">12</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; ====================================&#8217;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:print(tree:deleteNode($vBigTree4, 6)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">6</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:data(tree:deleteNode($vBigTree4, 6)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">6</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; ====================================&#8217;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:print(tree:deleteNode($vBigTree4, 5)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">5</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:data(tree:deleteNode($vBigTree4, 5)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">5</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; ====================================&#8217;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:print(tree:deleteNode($vBigTree4, 10)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:print</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">10</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#640064;">&#8216; tree:data(tree:deleteNode($vBigTree4, 10)): &#8216;</span></span></span><span style="font-family:times new roman;"><span style="font-size:x-small;"><span style="color:#000000;">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="color:#fa6400;">tree:data</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">tree:deleteNode</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">vBigTree4, </span><span style="color:#646464;">10</span></span></span><span style="font-family:times new roman;"><span style="color:#000000;font-size:x-small;">))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></p>
</td>
</tr>
</tbody>
</table>
<p>And here are the results:</p>
<table style="width:auto;border-collapse:collapse;background:#eefede;" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:print($vBigTree4):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">10</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">5</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">3</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">8</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">6</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">7</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">9</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">17</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">14</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">12</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">15</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">20</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:data($vBigTree4):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">3 5 6 7 8 9 10 12 14 15 17 20 </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">==================================== </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:print(tree:deleteNode($vBigTree4, 7)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;"></span></span></strong>&nbsp;</p>
<p style="line-height:13pt;margin:0 0 10pt;" class="MsoNormal"><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">10</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">5</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">3</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">8</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">6</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">9</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">17</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">14</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">12</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">15</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><font face="Times New Roman"><b><span style="line-height:14pt;"><font color="#993300">&lt;value&gt;</font></span></b><span style="line-height:14pt;"><font color="#000000">20</font></span><b><span style="line-height:14pt;"><font color="#993300">&lt;/value&gt;</font></span></b></font><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /><span><font color="#000000" face="Times New Roman">&nbsp;&nbsp; </font></span></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b><span style="line-height:14pt;"><br /></span><b><span style="line-height:14pt;"><font color="#993300" face="Times New Roman">&lt;/treeNode&gt;</font></span></b></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;"></span></span></strong>&nbsp;</p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:data(tree:deleteNode($vBigTree4, 7)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">3 5 6 8 9 10 12 14 15 17 20 </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">==================================== </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:print(tree:deleteNode($vBigTree4, 12)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">10</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">5</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">3</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">8</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">6</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">7</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">9</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">17</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">14</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">15</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">20</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:data(tree:deleteNode($vBigTree4, 12)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">3 5 6 7 8 9 10 14 15 17 20 </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">==================================== </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:print(tree:deleteNode($vBigTree4, 6)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">10</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">5</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">3</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">8</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">7</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">9</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">17</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">14</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">12</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">15</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">20</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:data(tree:deleteNode($vBigTree4, 6)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">3 5 7 8 9 10 12 14 15 17 20 </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">==================================== </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:print(tree:deleteNode($vBigTree4, 5)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">10</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">6</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">3</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">8</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">7</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">9</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">17</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">14</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">12</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">15</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">20</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:data(tree:deleteNode($vBigTree4, 5)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">3 6 7 8 9 10 12 14 15 17 20 </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">==================================== </span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:print(tree:deleteNode($vBigTree4, 10)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">9</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">5</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">3</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">8</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">6</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">7</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">17</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">14</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">12</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">15</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span><strong><span style="color:#000000;">20</span></strong><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">value</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:courier new;"><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">treeNode</span><span style="color:#0000ff;">&gt;</span></span></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">tree:data(tree:deleteNode($vBigTree4, 10)):</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><strong><span style="font-family:courier new;"><span style="color:#000000;">3 5 6 7 8 9 12 14 15 17 20</span></span></strong></p>
<p style="line-height:normal;margin:0;" class="MsoNormal"><span style="font-family:calibri;"><span style="color:#000000;">&nbsp;</span></span></p>
</td>
</tr>
</tbody>
</table>
<p>In my next posts I’ll show some of the most important applications of the Binary Search tree.</p>
<div style="position:absolute;width:1px;height:1px;overflow:hidden;top:0;left:-10000px;" id="_mcePaste" class="mcePaste">﻿</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=66&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2012/01/11/part-2-the-binary-search-data-structure-with-xpath-3-0-deleting-a-node/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>
	</item>
		<item>
		<title>The Binary Search Tree Data Structure&#8211;having fun with XPath 3.0</title>
		<link>http://dnovatchev.wordpress.com/2012/01/09/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/</link>
		<comments>http://dnovatchev.wordpress.com/2012/01/09/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 14:30:54 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[functional data structures]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[XPath 3.0]]></category>
		<category><![CDATA[XSLT 3.0]]></category>

		<guid isPermaLink="false">https://dnovatchev.wordpress.com/?p=54</guid>
		<description><![CDATA[For a long time I have wanted to play with XSLT 3.0 and XPath 3.0. Despite these being in their WD status, the new features are so powerful and overwhelming. Take just these: Higher Order Functions and the ability to &#8230; <a href="http://dnovatchev.wordpress.com/2012/01/09/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=54&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For a long time I have wanted to play with <a href="http://www.w3.org/TR/xslt-21/" target="_blank">XSLT 3.0</a> and <a href="http://www.w3.org/TR/xpath-30/" target="_blank">XPath 3.0</a>. Despite these being in their WD status, the new features are so powerful and overwhelming.</p>
<p><strong>Take just these</strong>: <a href="http://www.w3.org/TR/xpath-datamodel-30/#function-items" target="_blank">Higher Order Functions </a>and the ability to create <a href="http://www.w3.org/TR/xpath-30/#id-inline-func" target="_blank">new anonymous functions in XPath.</a></p>
<p>In my quest to accomplish what no one has ever done before with XPath I was helped by the existence of an early Saxon implementation – <a href="http://www.saxonica.com" target="_blank">Saxon 9.3.04 </a>offers these in its <a href="http://www.w3.org/TR/xquery-30/" target="_blank">XQuery 3.0</a> implementation and the <a href="http://www.w3.org/TR/xslt-21/" target="_blank">XSLT 3.0</a> implementation will hopefully be soon fully usable, after fixing a few bugs. The beautifully high-lighted XQuery code below was copied from <a href="http://www.oxygenxml.com/xquery.html" target="_blank">oXygen 12.1</a> and pasted onto <a href="http://office.microsoft.com/en-us/word/" target="_blank">Word</a>, then to <a href="http://explore.live.com/windows-live-writer?os=other" target="_blank">Windows Live Writer</a>.</p>
<p>I decided to start with something not too-complex (are you dreaming of a finger tree written entirely in XPath ?) and the Binary Search tree persistent functional data structure fits well this requirement.</p>
<p>So, let’s start:</p>
<p>As always:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">declare namespace</span><span style="color:#000000;"> tree </span><span style="color:#000096;">=</span><span style="color:#640064;"><a href="http://fxsl.sf.net">http://fxsl.sf.net</a></span><span style="color:#000000;">;</span></span></p>
</td>
</tr>
</tbody>
</table>
<p>A tree is a sequence (triple) of functions. Here is the definition of an empty tree:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span><strong><span style="color:#fa6400;">tree:tree</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()<br />
         </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">+</span></span></p>
<div class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#000000;">{<span style="font-family:Times New Roman;color:#000000;">  </span></span></div>
<div class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#000000;"><span style="font-family:Times New Roman;color:#000000;">  (</span></span><span style="font-family:Times New Roman;color:#000000;"><span style="font-family:Times New Roman;color:#000000;"><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {()},</span><span style="color:#008c00;">   (: top() :)</span></span><br />
<span style="font-family:Times New Roman;color:#000000;">    </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {()},</span><span style="color:#008c00;">   (: left() :)</span></span><br />
<span style="font-family:Times New Roman;color:#000000;">    </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() {()}</span><span style="color:#008c00;">    (: right() :)</span></span><br />
<span style="font-family:Times New Roman;"><span style="color:#000000;">  )<br />
};</span></span></span></span> </div>
</td>
</tr>
</tbody>
</table>
<p>The first function produces the <strong>top</strong> of the tree, which is the value ( <span style="font-family:Courier New;">item()</span> ) of its top node.</p>
<p>The second function produces the <strong>left </strong>sub-tree, which is another sequence (triple) of functions.</p>
<p>The third function produces the <strong>right </strong>sub-tree, which is another sequence (triple) of functions.</p>
<p>Do you see the problem with the type of the <span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:tree</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;">()</span></span>  function? What would happen if I accidentally returned only a pair of functions? Nothing! No static or runtime error would occur and I could spend a lot of time trying to find this simple error. Obviously, a <em>tuple</em> datatype would solve this problem completely.</p>
<p>Now, the three functions<span style="font-family:Courier New;"> top()</span>, <span style="font-family:Courier New;">left()</span> and<span style="font-family:Courier New;"> right()</span> :</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<div class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span></span></div>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#000000;"> tree:top<br />
         (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">?</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
 </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">pTree))<br />
   </span><strong><span style="color:#0000fa;">then</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;"> ()<br />
   </span><strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">     </span><span style="font-family:Times New Roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">]()<br />
};</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<div class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="color:#006400;">declare function</span></span></div>
<div><span style="font-family:Times New Roman;"><span style="font-family:Times New Roman;"><span style="color:#000000;">tree:left<br />
         (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
 </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">2</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">]))<br />
 </span><strong><span style="color:#0000fa;">then</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;"> ()<br />
 </span><strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">   </span><span style="font-family:Times New Roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">2</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">]()<br />
</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;"><span style="color:#000000;">};</span></span></span></span><span style="font-family:Times New Roman;"> </span> </div>
<div> </div>
<div><span style="font-family:Times New Roman;"><span style="color:#000000;"><span style="color:#000000;"><span style="color:#006400;">declare function<br />
</span></span></span></span><span style="font-family:Times New Roman;"><span style="color:#000000;"><span style="color:#000000;"><span style="font-family:Times New Roman;"><span style="color:#000000;">tree:right<br />
         (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><br />
<span style="color:#000000;"><span style="font-family:Times New Roman;">{<br />
 </span></span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong><span style="color:#000000;">(</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">3</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">]))<br />
   </span><strong><span style="color:#0000fa;">then</span></strong></span><span style="font-family:Times New Roman;"><span style="color:#000000;"> ()<br />
   </span><strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;color:#000000;">     </span><span style="font-family:Times New Roman;"><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">3</span></span><span style="font-family:Times New Roman;color:#000000;">]()<br />
};</span></span></span></span></div>
</td>
</tr>
</tbody>
</table>
<p>A tree is empty when:</p>
<table class="MsoTableGrid" style="width:auto;border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"><span style="color:#000000;"> tree:empty<br />
         (</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree </span><strong><span style="color:#fa6400;">as</span></strong><span style="color:#000000;"> (</span><strong><span style="color:#fa6400;">function</span></strong><span style="color:#000000;">() as </span><span style="color:#646464;">item</span><span style="color:#000000;">()</span><span style="color:#000096;">*</span><span style="color:#000000;">)</span><span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;"><span style="color:#000000;">)<br />
         as xs:boolean<br />
{<br />
 </span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree) </span><span style="color:#000096;">or</span><strong><span style="color:#fa6400;">empty</span></strong><span style="color:#000000;">(</span><span style="color:#000096;">$</span><span style="color:#000000;">pTree[</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;color:#000000;">]())<br />
};</span> </p>
</td>
</tr>
</tbody>
</table>
<p>When does a tree contain an item?</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"> tree:contains<br />
         (<span style="color:#000096;">$</span>pTree <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;">,<br />
          <span style="color:#000096;">$</span>pItem as <span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;">()<br />
         )<br />
         as xs:boolean<br />
{<br />
 <strong><span style="color:#0000fa;">if</span></strong>(<strong><span style="color:#fa6400;">tree:empty</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
   <strong><span style="color:#0000fa;">then</span></strong> <strong><span style="color:#fa6400;">false</span></strong></span><span style="font-family:Times New Roman;">()<br />
   <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">     </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong> <span style="color:#000096;">$</span>top <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)<br />
      <strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;">         (</span><span style="font-family:Times New Roman;"><span style="color:#000096;">$</span>pItem <span style="color:#000096;">eq</span> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">top)<br />
        <span style="color:#000096;">or</span></span><br />
<span style="font-family:Times New Roman;">         (</span><span style="font-family:Times New Roman;"><span style="color:#000096;">$</span>pItem <span style="color:#000096;">lt</span> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">top<br />
         <span style="color:#000096;">and</span></span><br />
<span style="font-family:Times New Roman;">          </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:contains</span></strong>(<strong><span style="color:#fa6400;">tree:left</span></strong>(<span style="color:#000096;">$</span>pTree),<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pItem)<br />
          )<br />
        <span style="color:#000096;">or</span></span><br />
<span style="font-family:Times New Roman;">         (</span><span style="font-family:Times New Roman;"><span style="color:#000096;">$</span>pItem <span style="color:#000096;">gt</span> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">top<br />
         <span style="color:#000096;">and</span></span><br />
<span style="font-family:Times New Roman;">          </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:contains</span></strong>(<strong><span style="color:#fa6400;">tree:right</span></strong>(<span style="color:#000096;">$</span>pTree),<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pItem)<br />
          )<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>How to add a new node to a tree?</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"> tree:insert<br />
         (<span style="color:#000096;">$</span>pTree <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;">,<br />
          <span style="color:#000096;">$</span>pItem as <span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;">()<br />
         )<br />
         <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">+</span></span><br />
<span style="font-family:Times New Roman;">{<br />
   </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<strong><span style="color:#fa6400;">tree:empty</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
      <strong><span style="color:#0000fa;">then</span></strong></span><br />
<span style="font-family:Times New Roman;">      (<br />
       </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong>() {<span style="color:#000096;">$</span>pItem},<span style="color:#008c00;">   (: top()   :)</span></span><br />
<span style="font-family:Times New Roman;">       </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:tree</span></strong>()},<span style="color:#008c00;">         (: left()  :)</span></span><br />
<span style="font-family:Times New Roman;">       </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:tree</span></strong>()}<span style="color:#008c00;">          (: right() :)</span></span><br />
<span style="font-family:Times New Roman;">       )<br />
      </span><strong><span style="font-family:Times New Roman;color:#0000fa;">else</span></strong><br />
<span style="font-family:Times New Roman;">       </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<span style="color:#000096;">$</span>pItem <span style="color:#000096;">lt</span> <strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
         <strong><span style="color:#0000fa;">then</span></strong></span><br />
<span style="font-family:Times New Roman;">          (<br />
           </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)},<br />
           <strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:insert</span></strong>(<strong><span style="color:#fa6400;">tree:left</span></strong>(<span style="color:#000096;">$</span>pTree), <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pItem)},<br />
           <strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:right</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)}<br />
           )<br />
         <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">          </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<span style="color:#000096;">$</span>pItem <span style="color:#000096;">gt</span> <strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
           <strong><span style="color:#0000fa;">then</span></strong></span><br />
<span style="font-family:Times New Roman;">           (<br />
            </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)},<br />
            <strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:left</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)},<br />
            <strong><span style="color:#fa6400;">function</span></strong>() {<strong><span style="color:#fa6400;">tree:insert</span></strong>(<strong><span style="color:#fa6400;">tree:right</span></strong>(<span style="color:#000096;">$</span>pTree), <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pItem)}<br />
           )<br />
           <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">            </span><span style="font-family:Times New Roman;color:#000096;">$</span><span style="font-family:Times New Roman;">pTree<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>How to present a tree?</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"> tree:print<br />
        (<span style="color:#000096;">$</span>pTree <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;">)<br />
        as <span style="color:#646464;">element</span>()<span style="color:#000096;">?</span></span><br />
<span style="font-family:Times New Roman;">{<br />
</span><span style="font-family:Times New Roman;">  </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<strong><span style="color:#fa6400;">not</span></strong>(<strong><span style="color:#fa6400;">tree:empty</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)))<br />
     <strong><span style="color:#0000fa;">then</span></strong></span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;"><span style="color:#000096;">&lt;</span>treeNode<span style="color:#000096;">&gt;</span></span><br />
<span style="font-family:Times New Roman;">           </span><span style="font-family:Times New Roman;"><span style="color:#000096;">&lt;</span>value<span style="color:#000096;">&gt;</span>{<strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span>pTree)}<span style="color:#000096;">&lt;/</span>value<span style="color:#000096;">&gt;</span></span><br />
<span style="font-family:Times New Roman;">           {<br />
            </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:print</span></strong>(<strong><span style="color:#fa6400;">tree:left</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)),<br />
            <strong><span style="color:#fa6400;">tree:print</span></strong>(<strong><span style="color:#fa6400;">tree:right</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
           }<br />
     <span style="color:#000096;">&lt;/</span>treeNode<span style="color:#000096;">&gt;</span></span><br />
<span style="font-family:Times New Roman;">     </span><strong><span style="font-family:Times New Roman;color:#0000fa;">else</span></strong><span style="font-family:Times New Roman;"> ()<br />
</span><span style="font-family:Times New Roman;">};</span></p>
</td>
</tr>
</tbody>
</table>
<p>How to atomize a tree (and get a good sorting function as a side effect)?</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#008c00;">(: tree:data()</span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">  Prints only the data &#8212; depth first.</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">   In effect this is sort() &#8212; quite good</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;">   for random data.</span></span><br />
<span style="color:#008c00;"><span style="font-family:Times New Roman;"> :)</span></span><br />
<span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"> tree:data<br />
        (<span style="color:#000096;">$</span>pTree <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;">)<br />
        as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span></span><br />
<span style="font-family:Times New Roman;">{<br />
   </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<strong><span style="color:#fa6400;">not</span></strong>(<strong><span style="color:#fa6400;">tree:empty</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)))<br />
     <strong><span style="color:#0000fa;">then</span></strong></span><br />
<span style="font-family:Times New Roman;">     (<br />
      </span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:data</span></strong>(<strong><span style="color:#fa6400;">tree:left</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)),<br />
      <strong><span style="color:#fa6400;">data</span></strong>(<strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)),<br />
      <strong><span style="color:#fa6400;">tree:data</span></strong>(<strong><span style="color:#fa6400;">tree:right</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
      )<br />
     <strong><span style="color:#0000fa;">else</span></strong></span><span style="font-family:Times New Roman;"> ()<br />
};</span></p>
</td>
</tr>
</tbody>
</table>
<p>How to return a subtree and its depth?</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#006400;">declare function</span><span style="font-family:Times New Roman;"> tree:findSubtree<br />
         (<span style="color:#000096;">$</span>pTree <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">*</span></span><span style="font-family:Times New Roman;">,<br />
          <span style="color:#000096;">$</span>pItem as <span style="color:#646464;">item</span></span><span style="font-family:Times New Roman;">()<br />
         )<br />
         <strong><span style="color:#fa6400;">as</span></strong> (<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span>)<span style="color:#000096;">*</span></span><br />
<span style="font-family:Times New Roman;">{<br />
 </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<strong><span style="color:#fa6400;">tree:empty</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree))<br />
   <strong><span style="color:#0000fa;">then</span></strong> (<strong><span style="color:#fa6400;">tree:tree</span></strong>(), <strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span> {<span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;">})<br />
   <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">     </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong> <span style="color:#000096;">$</span>depth <span style="color:#000096;">:=</span> <span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;">,<br />
         <span style="color:#000096;">$</span>top <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:top</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pTree)<br />
       <strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;">         </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<span style="color:#000096;">$</span>pItem <span style="color:#000096;">eq</span> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">top)<br />
           <strong><span style="color:#0000fa;">then</span></strong> (<span style="color:#000096;">$</span>pTree,<strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span> {<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">depth})<br />
           <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">             </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<span style="color:#000096;">$</span>pItem <span style="color:#000096;">lt</span> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">top)<br />
               <strong><span style="color:#0000fa;">then</span></strong></span><br />
<span style="font-family:Times New Roman;">                 </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">lsubtree<br />
                       <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<strong><span style="color:#fa6400;">tree:left</span></strong>(<span style="color:#000096;">$</span>pTree),<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pItem),<br />
                     <span style="color:#000096;">$</span>ldepth <span style="color:#000096;">:=</span> <span style="color:#000096;">$</span>lsubtree[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">]()<br />
                   <strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;">                     </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<span style="color:#000096;">$</span>ldepth <span style="color:#000096;">eq</span> <span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;">)<br />
                       <strong><span style="color:#0000fa;">then</span></strong> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">lsubtree<br />
                       <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">                         (</span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">subsequence</span></strong>(<span style="color:#000096;">$</span>lsubtree,<span style="color:#646464;">1</span>,<span style="color:#646464;">3</span></span><span style="font-family:Times New Roman;">),<br />
                          <strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span> {<span style="color:#646464;">1</span><span style="color:#000096;">+$</span></span><span style="font-family:Times New Roman;">ldepth}<br />
                          )<br />
               <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">                 </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">rsubtree<br />
                       <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<strong><span style="color:#fa6400;">tree:right</span></strong>(<span style="color:#000096;">$</span>pTree),<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">pItem),<br />
                     <span style="color:#000096;">$</span>rdepth <span style="color:#000096;">:=</span> <span style="color:#000096;">$</span>rsubtree[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">]()<br />
                   <strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;">                     </span><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">if</span></strong>(<span style="color:#000096;">$</span>rdepth <span style="color:#000096;">eq</span> <span style="color:#000096;">-</span><span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;">)<br />
                       <strong><span style="color:#0000fa;">then</span></strong> <span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">rsubtree<br />
                       <strong><span style="color:#0000fa;">else</span></strong></span><br />
<span style="font-family:Times New Roman;">                         (</span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">subsequence</span></strong>(<span style="color:#000096;">$</span>rsubtree,<span style="color:#646464;">1</span>,<span style="color:#646464;">3</span></span><span style="font-family:Times New Roman;">),<br />
                          <strong><span style="color:#fa6400;">function</span></strong>() as <span style="color:#646464;">item</span>()<span style="color:#000096;">*</span> {<span style="color:#646464;">1</span><span style="color:#000096;">+$</span></span><span style="font-family:Times New Roman;">rdepth}<br />
                          )</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><span style="font-family:Times New Roman;">};</span></span></p>
</td>
</tr>
</tbody>
</table>
<p>Finally, lets see how all this executes together:</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;"><strong><span style="color:#0000fa;">let</span></strong> <span style="color:#000096;">$</span>vEmptyTree <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:tree</span></strong></span><span style="font-family:Times New Roman;">(),<br />
    <span style="color:#000096;">$</span>vFilledTree <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:insert</span></strong>(<span style="color:#000096;">$</span>vEmptyTree,<span style="color:#646464;">5</span></span><span style="font-family:Times New Roman;">)  ,<br />
    <span style="color:#000096;">$</span>vFilledTree2 <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:insert</span></strong>(<span style="color:#000096;">$</span>vFilledTree,<span style="color:#646464;">3</span></span><span style="font-family:Times New Roman;">),  <br />
    <span style="color:#000096;">$</span>vFilledTree3 <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:insert</span></strong>(<span style="color:#000096;">$</span>vFilledTree2,<span style="color:#646464;">7</span></span><span style="font-family:Times New Roman;">),<br />
    <span style="color:#000096;">$</span>vFilledTree4 <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:insert</span></strong>(<span style="color:#000096;">$</span>vFilledTree3,<span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;">),<br />
    <span style="color:#000096;">$</span>vFilledTree5 <span style="color:#000096;">:=</span> <strong><span style="color:#fa6400;">tree:insert</span></strong>(<span style="color:#000096;">$</span>vFilledTree4,<span style="color:#646464;">9</span></span><span style="font-family:Times New Roman;">)<br />
    <strong><span style="color:#0000fa;">return</span></strong></span><br />
<span style="font-family:Times New Roman;">      (</span><span style="font-family:Times New Roman;"><strong><span style="color:#fa6400;">tree:print</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">vFilledTree5),<br />
       <span style="color:#640064;">&#8216; tree:contains($vFilledTree5,1): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:contains</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">1</span></span><span style="font-family:Times New Roman;">),<br />
       <span style="color:#640064;">&#8216; tree:contains($vFilledTree5,9): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:contains</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">9</span></span><span style="font-family:Times New Roman;">),<br />
       <span style="color:#640064;">&#8216; tree:contains($vFilledTree5,2): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:contains</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">2</span></span><span style="font-family:Times New Roman;">),<br />
       <span style="color:#640064;">&#8216; tree:contains($vFilledTree5,11): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:contains</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">11</span></span><span style="font-family:Times New Roman;">),<br />
       <span style="color:#640064;">&#8216; tree:findSubtree($vFilledTree5,9)[4](): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">9</span>)[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">](),<br />
       <span style="color:#640064;">&#8216; tree:findSubtree($vFilledTree5,1)[4](): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">1</span>)[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">](),<br />
       <span style="color:#640064;">&#8216; tree:findSubtree($vFilledTree5,3)[4](): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">3</span>)[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">](),<br />
       <span style="color:#640064;">&#8216; tree:findSubtree($vFilledTree5,7)[4](): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">7</span>)[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">](),<br />
       <span style="color:#640064;">&#8216; tree:findSubtree($vFilledTree5,5)[4](): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">5</span>)[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">](),<br />
       <span style="color:#640064;">&#8216; tree:findSubtree($vFilledTree5,12)[4](): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:findSubtree</span></strong>(<span style="color:#000096;">$</span>vFilledTree5,<span style="color:#646464;">12</span>)[<span style="color:#646464;">4</span></span><span style="font-family:Times New Roman;">](),<br />
       <span style="color:#640064;">&#8216; tree:data($vFilledTree5): &#8216;</span></span><span style="font-family:Times New Roman;">,<br />
       <strong><span style="color:#fa6400;">tree:data</span></strong>(<span style="color:#000096;">$</span></span><span style="font-family:Times New Roman;">vFilledTree5)<br />
      )</span></p>
</td>
</tr>
</tbody>
</table>
<p>And the result:</p>
<table class="MsoTableGrid" style="border-collapse:collapse;background:#ccffff;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="798">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">   </span><span style="font-family:Times New Roman;"><span style="color:#993300;">&lt;value&gt;</span>5<span style="color:#993300;">&lt;/value&gt;</span></span><br />
<span style="font-family:Times New Roman;">   </span><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;"><span style="color:#993300;">&lt;value&gt;</span>3<span style="color:#993300;">&lt;/value&gt;</span></span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">         </span><span style="font-family:Times New Roman;"><span style="color:#993300;">&lt;value&gt;</span>1<span style="color:#993300;">&lt;/value&gt;</span></span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">   </span><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">   </span><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;"><span style="color:#993300;">&lt;value&gt;</span>7<span style="color:#993300;">&lt;/value&gt;</span></span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;color:#993300;">&lt;treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">         </span><span style="font-family:Times New Roman;"><span style="color:#993300;">&lt;value&gt;</span>9<span style="color:#993300;">&lt;/value&gt;</span></span><br />
<span style="font-family:Times New Roman;">      </span><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">   </span><span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span><br />
<span style="font-family:Times New Roman;color:#993300;">&lt;/treeNode&gt;</span><br />
<span style="font-family:Times New Roman;">tree:contains($vFilledTree5,1):  true<br />
tree:contains($vFilledTree5,9):  true<br />
tree:contains($vFilledTree5,2):  false<br />
tree:contains($vFilledTree5,11):  false<br />
tree:findSubtree($vFilledTree5,9)[4]():  3<br />
tree:findSubtree($vFilledTree5,1)[4]():  3<br />
tree:findSubtree($vFilledTree5,3)[4]():  2<br />
tree:findSubtree($vFilledTree5,7)[4]():  2<br />
tree:findSubtree($vFilledTree5,5)[4]():  1<br />
tree:findSubtree($vFilledTree5,12)[4]():  -1<br />
tree:data($vFilledTree5):  1 3 5 7 9</span></p>
</td>
</tr>
</tbody>
</table>
<p>What next?</p>
<p>As you, my observant reader, probably have noticed, there is no <span style="font-family:Courier New;">tree:deleteItem()</span> yet. This is a little bit more tricky and will be the topic for my next post.</p>
<p><strong>Summary</strong>: A fully functional, persistent functional data structure – the Binary Search Tree has been implemented in pure XPath 3.0. We have observed how the new features of HOF and dynamically created anonymous function items make XPath 3.0 shine and how severely it lacks a simple yet most needed datatype – the tuple – to make our code more elegant and reliable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=54&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2012/01/09/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>
	</item>
		<item>
		<title>What words cannot describe</title>
		<link>http://dnovatchev.wordpress.com/2011/08/14/what-words-cannot-describe/</link>
		<comments>http://dnovatchev.wordpress.com/2011/08/14/what-words-cannot-describe/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 22:55:15 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Flowers]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/?p=104</guid>
		<description><![CDATA[Lillies in my garden: Is this the best? Or maybe this?<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=104&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lillies in my garden:</p>
<p><a href="http://dnovatchev.files.wordpress.com/2011/08/p1000408.jpg"><img class="alignnone size-large wp-image-105" title="P1000408" src="http://dnovatchev.files.wordpress.com/2011/08/p1000408.jpg?w=1024&#038;h=768" alt="" width="1024" height="768" /></a></p>
<p>Is this the best?</p>
<p><a href="http://dnovatchev.files.wordpress.com/2011/08/p1000412.jpg"><img class="alignnone size-large wp-image-106" title="P1000412" src="http://dnovatchev.files.wordpress.com/2011/08/p1000412.jpg?w=1024&#038;h=768" alt="" width="1024" height="768" /></a></p>
<p>Or maybe this?</p>
<p><a href="http://dnovatchev.files.wordpress.com/2011/08/p1000418.jpg"><img class="alignnone size-large wp-image-108" title="P1000418" src="http://dnovatchev.files.wordpress.com/2011/08/p1000418.jpg?w=1024&#038;h=768" alt="" width="1024" height="768" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/104/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=104&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2011/08/14/what-words-cannot-describe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>

		<media:content url="http://dnovatchev.files.wordpress.com/2011/08/p1000408.jpg?w=1024" medium="image">
			<media:title type="html">P1000408</media:title>
		</media:content>

		<media:content url="http://dnovatchev.files.wordpress.com/2011/08/p1000412.jpg?w=1024" medium="image">
			<media:title type="html">P1000412</media:title>
		</media:content>

		<media:content url="http://dnovatchev.files.wordpress.com/2011/08/p1000418.jpg?w=1024" medium="image">
			<media:title type="html">P1000418</media:title>
		</media:content>
	</item>
		<item>
		<title>Migrating to WordPress: http://dnovatchev.wordpress.com</title>
		<link>http://dnovatchev.wordpress.com/2010/11/21/migrating-to-wordpress-httpdnovatchev-wordpress-com/</link>
		<comments>http://dnovatchev.wordpress.com/2010/11/21/migrating-to-wordpress-httpdnovatchev-wordpress-com/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 18:45:00 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/2010/11/21/migrating-to-wordpress-httpdnovatchev-wordpress-com</guid>
		<description><![CDATA[As part of a global migration of spaces.live com to WordPress, I am migrating my blog to: http://dnovatchev.wordpress.com   Please, update your links, and sorry for the inconvenience.   From now on all my current and future posts will only be &#8230; <a href="http://dnovatchev.wordpress.com/2010/11/21/migrating-to-wordpress-httpdnovatchev-wordpress-com/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=5&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!44B0A32C2CCF7488!3551" class="bvMsg">
<div>As part of a <a href="http://explore.live.com/windows-live-spaces-transition-migrate" target="_blank">global migration of spaces.live com</a> to WordPress, I am migrating my blog to:<strong> </strong><a href="http://dnovatchev.wordpress.com/"><strong>http://dnovatchev.wordpress.com</strong></a></div>
<div> </div>
<div>Please, update your links, and sorry for the inconvenience. </div>
<div> </div>
<div>From now on all my current and future posts will only be available at: <a href="http://dnovatchev.wordpress.com/"><strong>http://dnovatchev.wordpress.com</strong></a></div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=5&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2010/11/21/migrating-to-wordpress-httpdnovatchev-wordpress-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>
	</item>
		<item>
		<title>The first Fibonacci Number that is zeroless-pandigital at both ends</title>
		<link>http://dnovatchev.wordpress.com/2010/09/13/the-first-fibonacci-number-that-is-zeroless-pandigital-at-both-ends/</link>
		<comments>http://dnovatchev.wordpress.com/2010/09/13/the-first-fibonacci-number-that-is-zeroless-pandigital-at-both-ends/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 13:24:35 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Project Euler]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/2010/09/13/the-first-fibonacci-number-that-is-zeroless-pandigital-at-both-ends</guid>
		<description><![CDATA[Here is another Project Euler problem – this time a little-bit more challenging: “The Fibonacci sequence is defined by the recurrence relation: Fn = Fn1 + Fn2 , where F1 = 1 and F2 = 1. It turns out that &#8230; <a href="http://dnovatchev.wordpress.com/2010/09/13/the-first-fibonacci-number-that-is-zeroless-pandigital-at-both-ends/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=6&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!44B0A32C2CCF7488!3545" class="bvMsg">
<div>
<p><strong>Here is another Project Euler problem – this time a little-bit more challenging</strong>: </p>
<table border="1" cellspacing="0" cellpadding="2" width="764" bgcolor="#f9fae4">
<tbody>
<tr>
<td valign="top" width="762">
<p>“<font color="#800040"><strong>The Fibonacci sequence is defined by the recurrence relation: </strong></font></p>
<blockquote><p><font color="#800040"><strong>F<sub><i>n</i></sub> = F<sub><i>n</i><img border="0" src="http://projecteuler.net/images/symbol_minus.gif" />1</sub> + F<sub><i>n</i><img border="0" src="http://projecteuler.net/images/symbol_minus.gif" />2 </sub>, where F<sub>1</sub> = 1 and F<sub>2</sub> = 1.</strong></font></p></blockquote>
<p><font color="#800040"><strong>It turns out that F<sub>541  </sub>, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F<sub>2749  </sub>, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital. </strong></font></p>
<p><font color="#800040"><strong>Given that F<sub><i>k</i></sub> is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find <i>k</i></strong></font>.”</p>
</p>
</p>
</p>
</p>
</p>
</p>
</td>
</tr>
</tbody>
</table>
<p><strong>Does this sound XSLT-ish? No, not at all</strong>.</p>
<p><em>This solution</em>:</p>
<table border="0" cellspacing="0" cellpadding="2" width="763">
<tbody>
<tr>
<td valign="top" width="761">
<table style="border-bottom:medium none;border-left:medium none;border-collapse:collapse;border-top:medium none;border-right:medium none;" border="1" cellspacing="0" cellpadding="0" width="764">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;width:6.65in;background:#ccecff;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="762">
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;">&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:stylesheet </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">version</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">2.0</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:xsl</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://www.w3.org/1999/XSL/Transform</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:xs</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://www.w3.org/2001/XMLSchema</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:f</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://fxsl.sf.net/</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:import </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">href</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">../../../f/func-Fibonacci.xsl</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:output </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">omit-xml-declaration</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">indent</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:template </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">match</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">/</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:getFiboBothEndingsPan9(3,2,1)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>  </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:template</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:getFiboBothEndingsPan9</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pcurrentInd</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pPrev1</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pPrev2</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">for $current in ($pPrev1 + $pPrev2) mod 1000000000</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>        </span>return</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>           </span>if(f:isPandigital19($current)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>and</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>              </span>f:isPandigital19Head(f:fibo($pcurrentInd))</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>              </span>)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>then $pcurrentInd</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>else</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>               </span>f:getFiboBothEndingsPan9($pcurrentInd+1, $current, $pPrev1)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>   </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:isPandigital19</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:boolean</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pN</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">for $s in xs:string($pN)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>    </span>return</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>          </span>not(translate(&#8217;123456789&#8242;, $s, &#8221;))</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>  </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:isPandigital19Head</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:boolean</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pN</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:isPandigital19(f:head9($pN))</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:head9</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">arg1</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>    </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer(substring(string($arg1), 1, 9))</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;">&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:stylesheet</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><strong>has the following properties</strong>:</p>
<ul>
<li><strong>Execution time</strong>:                 34.6 sec.
<li><strong>LOC</strong>:                                       54 (~ 40 express the solution)
<li><strong>Time to write the code</strong>:  ~15 min.
<li><strong>Uses library</strong>:                       <a href="http://fxsl.sf.net/"><strong>FXSL</strong></a> (the<strong> </strong><a href="http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-Fibonacci.xsl?revision=1.3&amp;view=markup"><strong>f:fibo()</strong> </a>function for generating Fibonacci numbers)</li>
</li>
</li>
</li>
</ul>
<p>The index of the first Fibonacci number with the required properties is more than 300 thousand and the number itself has more than 68 thousand digits.</p>
<p><strong>Not satisfied with the speed of this solution? Want even faster? Then here’s something you may consider</strong>:</p>
<table border="0" cellspacing="0" cellpadding="2" width="735">
<tbody>
<tr>
<td valign="top" width="733">
<table style="border-bottom:medium none;border-left:medium none;border-collapse:collapse;border-top:medium none;border-right:medium none;" border="1" cellspacing="0" cellpadding="0" width="735">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;width:6.65in;background:#ccecff;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="733">
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;">&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:stylesheet </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">version</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">2.0</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:xsl</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://www.w3.org/1999/XSL/Transform</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:xs</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://www.w3.org/2001/XMLSchema</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:f</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://fxsl.sf.net/</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:output </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">omit-xml-declaration</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">indent</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:template </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">match</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">/</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:sequence select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:getFiboBothEndingsPan9(3,2,1,2,1)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>  </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:template</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:function name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:getFiboBothEndingsPan9</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pcurrentInd</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pPrevTail1</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pPrevTail2</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pPrevHead1</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pPrevHead2</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:sequence select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">for $currentTail in ($pPrevTail1 + $pPrevTail2) mod 1000000000,</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>  </span><span>      </span>$newHead1 in $pPrevHead1 + $pPrevHead2,</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>        </span>$newHead2 in $pPrevHead1,</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>        </span>$currentHead1 in if($newHead1 ge 10000000000000000)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>                           </span>then $newHead1 idiv 10</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>                           </span>else $newHead1,</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>        </span>$currentHead2 in if($newHead1 ge 10000000000000000)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>                            </span>then $newHead2 idiv 10</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>                            </span>else $newHead2</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>        </span>return</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>           </span>if($currentHead1 ge 100000000</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>and</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>              </span>f:isPandigital19($currentTail)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>and</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>              </span>f:isPandigital19</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;">                    (xs:integer(substring(string($currentHead1),1,9)))</span></b><b><span style="font-family:'Courier New';color:black;font-size:10pt;">)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>then $pcurrentInd</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>             </span>else</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>               </span>f:getFiboBothEndingsPan9($pcurrentInd+1, </span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;">                                        $currentTail, $pPrevTail1,</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>          </span><span>                              </span>$currentHead1, $currentHead2</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>                                        </span>)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>   </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:function</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:function name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">f:isPandigital19</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:boolean</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pN</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:sequence select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">for $s in xs:string($pN)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>    </span>return</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>          </span>not(translate(&#8217;123456789&#8242;, $s, &#8221;))</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>  </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">xsl:function</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;">&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:stylesheet</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>We have added a a couple of lines of code and look what we have now:</p>
<ul>
<li><strong>Execution time</strong>:                     0.555 sec.
<li><strong>LOC</strong>:                                        55 (~ 43 express the solution)
<li><strong>Time to write the code</strong>:  ~10 min.</li>
</li>
</li>
</ul>
<p>As witnessed in the Project Euler thread for this problem (one must have provided the correct answer in order to access this thread), many solutions took longer: from 3.3 seconds, to 30-40 minutes, to couple of hours. </p>
<p>One Python programmer even waited for the end of his brute-force solution … 12 days <img src="http://shared.live.com/PTgijnjzs3RZfNgSVvcPUQ/emoticons/smile_regular.gif" /></p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=6&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2010/09/13/the-first-fibonacci-number-that-is-zeroless-pandigital-at-both-ends/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>

		<media:content url="http://projecteuler.net/images/symbol_minus.gif" medium="image" />

		<media:content url="http://projecteuler.net/images/symbol_minus.gif" medium="image" />

		<media:content url="http://shared.live.com/PTgijnjzs3RZfNgSVvcPUQ/emoticons/smile_regular.gif" medium="image" />
	</item>
		<item>
		<title>Not for XSLT? More Fun with Project Euler</title>
		<link>http://dnovatchev.wordpress.com/2010/08/30/not-for-xslt-more-fun-with-project-euler/</link>
		<comments>http://dnovatchev.wordpress.com/2010/08/30/not-for-xslt-more-fun-with-project-euler/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 12:23:31 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Project Euler]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/2010/08/30/not-for-xslt-more-fun-with-project-euler</guid>
		<description><![CDATA[  Here is another Project Euler problem that seems exactly what XSLT was not intended for:   In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by only moving to &#8230; <a href="http://dnovatchev.wordpress.com/2010/08/30/not-for-xslt-more-fun-with-project-euler/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=8&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!44B0A32C2CCF7488!3540" class="bvMsg">
<p> </p>
<p><strong>Here is another Project Euler problem that seems exactly what XSLT was not intended for</strong>:</p>
<p> </p>
<div><font color="#0000a0">In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by <b>only moving to the right and down</b>, is indicated in bold red and is equal to 2427</font>.</p>
</div>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0" width="290" align="center">
<tbody>
<tr>
<td width="39">
<p><a href="http://dnovatchev.files.wordpress.com/2010/08/028c640586c52bfd33ad8f1c1ee9e8c1.png" rel="WLPP"><img border="0" src="http://dnovatchev.files.wordpress.com/2010/08/028c640586c52bfd33ad8f1c1ee9e8c1.png?w=10" /></a>   </p>
</td>
<td width="202">
<table border="0" cellspacing="0" cellpadding="0" width="214">
<tbody>
<tr>
<td>
<p><b><font color="#ff0000">131</font></b></p>
</td>
<td>
<p>673</p>
</td>
<td>
<p>234</p>
</td>
<td width="61">
<p>103</p>
</td>
<td width="58">
<p>18</p>
</td>
</tr>
<tr>
<td>
<p><b><font color="#ff0000">201</font></b></p>
</td>
<td>
<p><b><font color="#ff0000">96</font></b></p>
</td>
<td>
<p><b><font color="#ff0000">342</font></b></p>
</td>
<td width="61">
<p>965</p>
</td>
<td width="58">
<p>150</p>
</td>
</tr>
<tr>
<td>
<p>630</p>
</td>
<td>
<p>803</p>
</td>
<td>
<p><b><font color="#ff0000">746</font></b></p>
</td>
<td width="61">
<p><b><font color="#ff0000">422</font></b></p>
</td>
<td width="58">
<p>111</p>
</td>
</tr>
<tr>
<td>
<p>537</p>
</td>
<td>
<p>699</p>
</td>
<td>
<p>497</p>
</td>
<td width="61">
<p><b><font color="#ff0000">121</font></b></p>
</td>
<td width="58">
<p>956</p>
</td>
</tr>
<tr>
<td>
<p>805</p>
</td>
<td>
<p>732</p>
</td>
<td>
<p>524</p>
</td>
<td width="61">
<p><b><font color="#ff0000">37</font></b></p>
</td>
<td width="58">
<p><b><font color="#ff0000">331</font></b></p>
</td>
</tr>
</tbody>
</table>
</td>
<td width="57">
<p>   <a href="http://dnovatchev.files.wordpress.com/2010/08/323f2a7b5722674aa62e1f37de3a8c50.png" rel="WLPP"><img border="0" src="http://dnovatchev.files.wordpress.com/2010/08/323f2a7b5722674aa62e1f37de3a8c50.png?w=10" /></a></p>
</td>
</tr>
</tbody>
</table>
</div>
<div align="center"> </div>
<p><font color="#0000a0">Find the minimal path sum, in </font><a href="http://projecteuler.net/project/matrix.txt"><font color="#0000a0">matrix.txt</font></a><font color="#0000a0"> (right click and &#8216;Save Link/Target As&#8230;&#8217;), a 31K text file containing a 80 by 80 matrix, from the top left to the bottom right by only moving right and down</font>. </p>
<p><strong>My solution</strong>:</p>
<p> </p>
<table style="border-bottom:medium none;border-left:medium none;border-collapse:collapse;border-top:medium none;border-right:medium none;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;width:378.9pt;background:#ccecff;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding:0 5.4pt;" valign="top" width="632">
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;">&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:stylesheet </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">version</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">2.0</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:xsl</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://www.w3.org/1999/XSL/Transform</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:xs</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://www.w3.org/2001/XMLSchema</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:saxon</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">http://saxon.sf.net/</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span><span style="font-family:'Courier New';color:red;font-size:10pt;">xmlns:mx</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:red;font-size:10pt;">my:my</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">exclude-result-prefixes</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs saxon mx</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:output </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">omit-xml-declaration</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">indent</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:variable </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">vMatrix</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">element()*</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:variable </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">vLines</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:string*</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">tokenize(unparsed-text(&#8216;matrix.txt&#8217;),&#8217;\s+&#8217;)[.]</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:for-each </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">$vLines</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>     </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">line</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>      </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:for-each </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">tokenize(.,&#8217;,')</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>        </span>&lt;</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">v</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:value-of </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">.</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;&lt;/</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">v</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>      </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:for-each</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>     </span>&lt;/</span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">line</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:for-each</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:variable</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:variable </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">vDimension</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">count($vMatrix)</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:template </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">match</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">/</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">mx:path-minSum(1,1,0)</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:template</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">mx:path-minSum</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">saxon:memo-function</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pX</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pY</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pcurSum</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:variable </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">curVal</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">mx:mtx($pX, $pY)</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>   </span>&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">if($pX eq $vDimension and $pY eq $vDimension)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span>then $curVal</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span>else</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>        </span>for $nextX in min(($vDimension, $pX+1)),</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>            </span>$nextY in min(($vDimension, $pY+1)),</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>            </span>$s1 in </span></b><b><span style="font-family:'Courier New';color:black;font-size:10pt;">if($nextY gt $pY)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>              </span>then</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>               </span>$pcurSum + $curVal</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>               </span>+ mx:path-minSum($pX, $nextY, $pcurSum)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>              </span>else 999999999999,</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>            </span>$s2 in if($nextX gt $pX)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>              </span>then</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>               </span>$pcurSum + $curVal</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>               </span>+ mx:path-minSum($nextX, $pY, $pcurSum)</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>      </span><span>              </span>else 999999999999</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>          </span>return</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>            </span>min(($s1,$s2))</span></b></p>
<p style="line-height:normal;margin-bottom:0;"><b><span style="font-family:'Courier New';color:black;font-size:10pt;"><span>   </span></span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">mx:mtx</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span><span style="font-family:'Courier New';color:maroon;font-size:10pt;">saxon:memo-function</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">yes</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pX</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:param </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">name</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">pY</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot; </span><span style="font-family:'Courier New';color:purple;font-size:10pt;">as</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">xs:integer</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span></span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span>  </span>&lt;</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:sequence </span></b><span style="font-family:'Courier New';color:purple;font-size:10pt;">select</span><span style="font-family:'Courier New';color:blue;font-size:10pt;">=&quot;</span><b><span style="font-family:'Courier New';color:black;font-size:10pt;">$vMatrix[$pY]/*[$pX]</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&quot;/&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;"><span> </span>&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:function</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span style="font-family:'Courier New';color:blue;font-size:10pt;">&lt;/</span><b><span style="font-family:'Courier New';color:purple;font-size:10pt;">xsl:stylesheet</span></b><span style="font-family:'Courier New';color:blue;font-size:10pt;">&gt;</span></p>
<p style="line-height:normal;margin-bottom:0;"><span lang="EN"> </span></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p><strong>Properties</strong>:</p>
<ul>
<li><strong>LOC</strong>:                                         65 – well-formatted code for readability.</li>
<li><strong>Execution time</strong>:                  078 ms.</li>
<li><strong>Time to write the code</strong>:  ~ 10 minutes.</li>
</ul>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=8&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2010/08/30/not-for-xslt-more-fun-with-project-euler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>

		<media:content url="http://dnovatchev.files.wordpress.com/2010/08/028c640586c52bfd33ad8f1c1ee9e8c1.png?w=10" medium="image" />

		<media:content url="http://dnovatchev.files.wordpress.com/2010/08/323f2a7b5722674aa62e1f37de3a8c50.png?w=10" medium="image" />
	</item>
		<item>
		<title>Fun with Project Euler</title>
		<link>http://dnovatchev.wordpress.com/2010/06/16/fun-with-project-euler/</link>
		<comments>http://dnovatchev.wordpress.com/2010/06/16/fun-with-project-euler/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 04:55:17 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Project Euler]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/2010/06/16/fun-with-project-euler</guid>
		<description><![CDATA[I have been having fun solving some Project Euler problems. Most of my 76 solutions were done in XSLT 2.0 last year. For those who are busy arguing whether or not  XSLT is a programming language, here is one easy &#8230; <a href="http://dnovatchev.wordpress.com/2010/06/16/fun-with-project-euler/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=7&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!44B0A32C2CCF7488!3526" class="bvMsg">
<p>I have been having fun solving some<strong> </strong><a href="http://projecteuler.net/"><strong>Project Euler</strong></a> <em><strong><a href="http://projecteuler.net/index.php?section=problems">problems</a></strong></em>. Most of my 76 solutions were done in XSLT 2.0 last year. </p>
<p>For those who are busy arguing whether or not  XSLT is a programming language, here is one easy problem:</p>
<p><em><font color="#800080"><strong>The 5-digit number, 16807=7<sup>5</sup>, is also a fifth power. Similarly, the 9-digit number, 134217728=8<sup>9</sup>, is a ninth power.</strong></font></em> </p>
<p><em><font color="#800080"><strong>How many n-digit positive integers exist which are also an nth power?</strong></font></em> </p>
<p>Below is the solution, and it takes 20ms to run with Saxon 9.1.07: </p>
<table border="0" cellspacing="0" cellpadding="2" width="558" bgcolor="#cef4f9">
<tbody>
<tr>
<td valign="top" width="556"><span style="background-color:#cef4f9;font-family:courier new;color:#000000;font-size:10pt;"><span style="background-color:#cef4f9;color:#0000ff;">&lt;</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:stylesheet</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"> </span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"></span><span style="background-color:#cef4f9;color:#800080;">version</span><span style="background-color:#cef4f9;color:#0000ff;">=&quot;</span><span style="background-color:#cef4f9;color:#000000;font-weight:bold;">2.0</span><span style="background-color:#cef4f9;color:#0000ff;">&quot;<br /></span><span style="background-color:#cef4f9;color:#ff0000;">xmlns:xsl</span><span style="background-color:#cef4f9;color:#0000ff;">=</span><span style="background-color:#cef4f9;color:#ff0000;font-weight:bold;"><a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a></span><span style="background-color:#cef4f9;color:#0000ff;"><br /></span><span style="background-color:#cef4f9;color:#ff0000;">xmlns:f</span><span style="background-color:#cef4f9;color:#0000ff;">=</span><span style="background-color:#cef4f9;color:#ff0000;font-weight:bold;"><a href="http://fxsl.sf.net/">http://fxsl.sf.net/</a></span><span style="background-color:#cef4f9;color:#0000ff;">&gt;<br /></span><span style="background-color:#cef4f9;color:#0000ff;"><br /></span><span style="background-color:#cef4f9;color:#0000ff;">&lt;</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:import</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"> </span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"></span><span style="background-color:#cef4f9;color:#800080;">href</span><span style="background-color:#cef4f9;color:#0000ff;">=&quot;</span><span style="background-color:#cef4f9;color:#000000;font-weight:bold;">../../../f/func-exp.xsl</span><span style="background-color:#cef4f9;color:#0000ff;">&quot;/&gt;<br /></span><span style="background-color:#cef4f9;color:#0000ff;"><br /></span><span style="background-color:#cef4f9;color:#0000ff;">&lt;</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:output</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"> </span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"></span><span style="background-color:#cef4f9;color:#800080;">method</span><span style="background-color:#cef4f9;color:#0000ff;">=&quot;</span><span style="background-color:#cef4f9;color:#000000;font-weight:bold;">text</span><span style="background-color:#cef4f9;color:#0000ff;">&quot;/&gt;</p>
<p></span><span style="background-color:#cef4f9;color:#0000ff;">&lt;</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:template</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"> </span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"></span><span style="background-color:#cef4f9;color:#800080;">match</span><span style="background-color:#cef4f9;color:#0000ff;">=&quot;</span><span style="background-color:#cef4f9;color:#000000;font-weight:bold;">/</span><span style="background-color:#cef4f9;color:#0000ff;">&quot;&gt;<br /></span><span style="background-color:#cef4f9;color:#0000ff;">  &lt;</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:sequence</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"> </span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;"></span><span style="background-color:#cef4f9;color:#800080;">select</span><span style="background-color:#cef4f9;color:#0000ff;">=<br />   &quot;</span><span style="background-color:#cef4f9;color:#000000;font-weight:bold;">(: count( :)<br />       for $k in 1 to 9,<br />           $n in 1 to 23,<br />           $k-pwr-n in f:intppow($k,$n),<br />           $low in f:intppow(10,$n -1) -1,<br />           $high in f:intppow(10,$n)<br />        return<br />          if($k-pwr-n gt $low and $k-pwr-n lt $high)<br />           then ($k, $n, $k-pwr-n, &#8216;</span><span style="background-color:#cef4f9;font-style:italic;color:#000000;font-weight:bold;">&#xA;</span><span style="background-color:#cef4f9;color:#000000;font-weight:bold;">&#8216;)<br />           else()<br />   (: ) :)<br /></span><span style="background-color:#cef4f9;color:#0000ff;">   &quot;/&gt;<br /></span><span style="background-color:#cef4f9;color:#0000ff;">&lt;/</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:template</span><span style="background-color:#cef4f9;color:#0000ff;">&gt;<br />&lt;/</span><span style="background-color:#cef4f9;color:#800080;font-weight:bold;">xsl:stylesheet</span><span style="background-color:#cef4f9;color:#0000ff;">&gt;<br /></span></span></td>
</tr>
</tbody>
</table>
<p><span style="background-color:#cef4f9;font-family:courier new;color:#000000;font-size:10pt;"><span style="background-color:#cef4f9;color:#000000;font-weight:bold;"></span></span> </p>
<p><strong><a href="http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-exp.xsl?revision=1.4&amp;view=markup">f:intppow(k, n)</a></strong>  is an <a href="http://fxsl.sf.net/"><strong>FXSL 2.x</strong></a> function with positive integer arguments that calculates <strong>k<sup>n.</sup></strong></p>
<p><sup>And if all this is possible even now, imagine yourself working with XSLT 2.1 in the near future&#8230; <img src="http://shared.live.com/5oeCPTazLAJxhccDO!c5Cg/emoticons/smile_regular.gif" /></sup></p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=7&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2010/06/16/fun-with-project-euler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>

		<media:content url="http://shared.live.com/5oeCPTazLAJxhccDO!c5Cg/emoticons/smile_regular.gif" medium="image" />
	</item>
		<item>
		<title>Should XPath have virtual axes?</title>
		<link>http://dnovatchev.wordpress.com/2010/02/08/should-xpath-have-virtual-axes/</link>
		<comments>http://dnovatchev.wordpress.com/2010/02/08/should-xpath-have-virtual-axes/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:17:11 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/2010/02/08/should-xpath-have-virtual-axes</guid>
		<description><![CDATA[In his recent blog-article: “XPath needs virtual axes. Making XPath more XPathy?” Rick Jelliffe sais: “I really like XPath2. I would never recommend anyone start with XPath1, unless you were doing very basic transformations with no text processing or data &#8230; <a href="http://dnovatchev.wordpress.com/2010/02/08/should-xpath-have-virtual-axes/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=17&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!44B0A32C2CCF7488!2518" class="bvMsg">
<p>In his recent blog-article: “<a href="http://broadcast.oreilly.com/2010/02/xpath-needs-virtual-axes.html" target="_blank">XPath needs virtual axes. Making XPath more XPathy?</a>” <a href="http://www.oreillynet.com/pub/au/1712">Rick Jelliffe</a> sais:</p>
<blockquote>
<p>“<em>I really like XPath2. I would never recommend anyone start with XPath1, unless you were doing very basic transformations with no text processing or data formatting. </em></p>
<p><em>But the niggle I have with XPath2 is that it is less XPath-y than XPath1. It does not significantly improve the central syntactical feature of XPaths: the location steps. (The only improvement that springs to mind is that XPath2 did improve the use of parentheses in location steps.) Instead, XPath2 provided much more conventional features like a <tt>for</tt> iterator. I think these significantly decrease the comprehensibility of an XPath, are anonymous and therefore require may comments to explain them, and fracture the line. To an extent, once you start to use nested syntaxes and iterators, why both using XPath at all</em>?”</p>
</blockquote>
<p>Rick gives this example: </p>
<blockquote>
<p><font face="Courier New"><strong>find-rep( find-client(//manager/clients/client-ref)/rep-ref)/name</strong></font></p>
</blockquote>
<p>and proposes to improve the expression above by introducing “virtual axes” so that it could be written as: </p>
<blockquote>
<p><font face="Courier New"><strong>//manager/clients/client-ref/find-client::rep-ref/find-rep::rep/name</strong></font></p>
</blockquote>
<p>So, curious reader, pause for a while, don’t read below, and think: has Rick uncovered a hole in XPath?  </p>
<p><strong><a href="http://broadcast.oreilly.com/2010/02/xpath-needs-virtual-axes.html#comment-2318334" target="_blank">Here is my answer</a></strong>: </p>
<blockquote>
<p>What you are asking for can be expressed almost exactly in the same form (actually I prefer the current XPath 2.0 form of expression). </p>
<p>You are asking for: </p>
</blockquote>
<blockquote style="margin-right:0;">
<blockquote>
<p><font color="#974806" size="1" face="Courier New"><strong>//manager/clients/client-ref/find-client::rep-ref/find-rep::rep/name</strong></font></p>
</blockquote>
</blockquote>
<blockquote>
<p>One can write this in XPath 2.0 as: </p>
<blockquote style="margin-right:0;">
<p><font><font color="#008000" size="1" face="Courier New"><strong>//manager/clients/client-ref/find-client(.)/rep-ref/find-rep(.)/name</strong></font> </font></p>
</blockquote>
<p><strong>The current XPath way of expressing this is cleaner &#8212; no need for virtual axes</strong>. </p>
<p>This is a feature of XPath 2.0 that is not widely used and known: any function can be used as the current location step. The syntax rules that resolve its use are (at <a href="http://www.w3.org/TR/2007/REC-xpath20-20070123/#id-grammar):">http://www.w3.org/TR/2007/REC-xpath20-20070123/#id-grammar):</a> </p>
<blockquote style="margin-right:0;">
<p>[27] StepExpr ==&gt; [38] FilterExpr ==&gt; [41] PrimaryExpr </p>
</blockquote>
<p>and the fact that a <font face="Courier New"><strong>FunctionCall</strong></font> is a <font face="Courier New"><strong>PrimaryExpr</strong></font>: </p>
<blockquote style="margin-right:0;">
<p><a></a><font size="2">[41]   <code><a href="http://www.w3.org/#doc-xpath-PrimaryExpr">PrimaryExpr</a></code>   ::=   <code><a href="http://www.w3.org/#prod-xpath-Literal">Literal</a> | <a href="http://www.w3.org/#prod-xpath-VarRef">VarRef</a> | <a href="http://www.w3.org/#prod-xpath-ParenthesizedExpr">ParenthesizedExpr</a> | <a href="http://www.w3.org/#prod-xpath-ContextItemExpr">ContextItemExpr</a> | <a href="http://www.w3.org/#prod-xpath-FunctionCall">FunctionCall</a></code></font></p>
</blockquote>
</p>
</p>
</p>
</p>
</p>
</p>
</p>
</blockquote>
<p>  </p>
<p>Also, consider that the axes in XPath have been useful so far mainly because there are just a few of them. Imagine having to deal with zillions of axes and struggling to remember what they mean. And if everyone can introduce their own axes, then why bother with them at all?</p>
<p>Dear reader, it&#8217;s up to you to decide&#8230; as I have already done.</p>
</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=17&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2010/02/08/should-xpath-have-virtual-axes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>
	</item>
		<item>
		<title>Optimized Repetitive Prepends, Part III: Understanding the Solution</title>
		<link>http://dnovatchev.wordpress.com/2008/12/24/optimized-repetitive-prepends-part-iii-understanding-the-solution/</link>
		<comments>http://dnovatchev.wordpress.com/2008/12/24/optimized-repetitive-prepends-part-iii-understanding-the-solution/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 18:23:19 +0000</pubDate>
		<dc:creator>Dimitre Novatchev</dc:creator>
				<category><![CDATA[Performance Optimization]]></category>

		<guid isPermaLink="false">http://dnovatchev.wordpress.com/2008/12/24/optimized-repetitive-prepends-part-iii-understanding-the-solution</guid>
		<description><![CDATA[  Technorati Tags: performance optimization, algorithms, algorithmic complexity, functional programming In Part II of this post a solution was given to the problem presented in Part I: &#34;Can we implement an algorithm for repetitive prepends that will be run by &#8230; <a href="http://dnovatchev.wordpress.com/2008/12/24/optimized-repetitive-prepends-part-iii-understanding-the-solution/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=10&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="msgcns!44B0A32C2CCF7488!981" class="bvMsg">
<p>  </p>
<div style="display:inline;margin:0;padding:0;">Technorati Tags: <a href="http://technorati.com/tags/performance optimization" rel="tag">performance optimization</a>, <a href="http://technorati.com/tags/algorithms" rel="tag">algorithms</a>, <a href="http://technorati.com/tags/algorithmic complexity" rel="tag">algorithmic complexity</a>, <a href="http://technorati.com/tags/functional programming" rel="tag">functional programming</a></div>
<p>In <a href="http://dnovatchev.spaces.live.com/Blog/cns!44B0A32C2CCF7488!980.entry" target="_blank"><strong>Part II</strong></a> of this post a solution was given to the problem presented in <a href="http://dnovatchev.spaces.live.com/Blog/cns!44B0A32C2CCF7488!977.entry" target="_blank"><strong>Part I</strong></a>: </p>
<p>&quot;<em><strong>Can we implement an algorithm for repetitive prepends that will be run by P1 in linear time, in addition to its excellent linear performance of repetitive appends</strong></em>?&quot; </p>
<p>The solution is implemented within the function <font face="Courier New" size="3"><strong>my:prepend-iter()</strong></font> that is defined in the following way: </p>
<table style="border-right:medium none;border-top:medium none;background:#daeef3;border-left:medium none;border-bottom:medium none;border-collapse:collapse;margin:auto auto auto .9pt;" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td style="border-right:black 1pt solid;border-top:black 1pt solid;border-left:black 1pt solid;width:5in;border-bottom:black 1pt solid;background-color:transparent;padding:0 5.4pt;" valign="top" width="600">
<p style="margin:0;"><b><span style="font-size:10pt;font-family:'Courier New';"><span><font color="#000000">      </font></span></span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&lt;</span><b><span style="font-size:10pt;color:purple;font-family:'Courier New';">xsl:function </span></b><span style="font-size:10pt;color:purple;font-family:'Courier New';">name</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">my:prepend-iter</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot;&gt;</span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"><span>        </span>&lt;</span><b><span style="font-size:10pt;color:purple;font-family:'Courier New';">xsl:param </span></b><span style="font-size:10pt;color:purple;font-family:'Courier New';">name</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">pNumTimes</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot; </span><span style="font-size:10pt;color:purple;font-family:'Courier New';">as</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">xs:integer</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot;/&gt;</span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"><span>        </span>&lt;</span><b><span style="font-size:10pt;color:purple;font-family:'Courier New';">xsl:param </span></b><span style="font-size:10pt;color:purple;font-family:'Courier New';">name</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">pstartSeq</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot; </span><span style="font-size:10pt;color:purple;font-family:'Courier New';">as</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">element()*</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot;/&gt;</span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"><span>        </span>&lt;</span><b><span style="font-size:10pt;color:purple;font-family:'Courier New';">xsl:param </span></b><span style="font-size:10pt;color:purple;font-family:'Courier New';">name</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">pInserts</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot; </span><span style="font-size:10pt;color:purple;font-family:'Courier New';">as</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">element()*</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot;/&gt;</span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"> </span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"><span>          </span>&lt;</span><b><span style="font-size:10pt;color:purple;font-family:'Courier New';">xsl:sequence </span></b><span style="font-size:10pt;color:purple;font-family:'Courier New';">select</span><span style="font-size:10pt;color:blue;font-family:'Courier New';">=</span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"><span>           </span>&quot;</span><b><span style="font-size:10pt;color:black;font-family:'Courier New';">if($pNumTimes gt 0)</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>               </span>then</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>                 </span>my:prepend-iter</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>                        </span>($pNumTimes -1,</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>                         </span>$pstartSeq,</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>                         </span>($pInserts, reverse($vPrepends) )</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>                         </span>)</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>               </span>else</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>                 </span>(reverse($pInserts), $pstartSeq)</span></b> </p>
<p style="margin:0;"><b><span style="font-size:10pt;color:black;font-family:'Courier New';"><span>            </span></span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&quot;/&gt;</span> </p>
<p style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';"><span>      </span>&lt;/</span><b><span style="font-size:10pt;color:purple;font-family:'Courier New';">xsl:function</span></b><span style="font-size:10pt;color:blue;font-family:'Courier New';">&gt;</span><span></span></tbody>
</table>
<p>The first argument passed to this function, <b>pNumTimes,</b> is the number of times to perform the prepend operation on the initial sequence <b>pstartSeq, </b>which is passed as the second argument. </p>
<p>The third argument has an auxiliary purpose. As its name, <b>pInserts </b>suggests, it contains the accumulation of all sequences that are to be prepended to <b>pstartSeq</b>. </p>
<p>The idea is to produce the final result only when <b>pNumTimes</b>  is zero, using at this time the accumulated prepends in <b>pInserts </b>and the initial sequence <b>pstartSeq</b>. </p>
<p><em><strong>The idea of the algorithm is to replace the repetitive prepend operations with repetitive append operations, which are carried out by the xslt processor with linear complexity</strong></em>. </p>
<p>We notice that: </p>
<p><font face="Courier New"><strong>y2s ++ y1s ++ xs   =</strong></font> </p>
<p><font face="Courier New"><strong>reverse(  reverse(y1s) ++ reverse(y2s) ) ++ xs</strong></font>       <strong>(1)</strong> </p>
<p>Or in general, if we have N sequences: </p>
<p><font face="Courier New"><strong>y1s, y2s, &#8230;, yNs</strong></font>  </p>
<p>to be prepended to an initial sequence xs in that order, </p>
<p><font face="Courier New"><strong>yNs ++ yN-1s ++ &#8230; y2s ++ y1s ++ xs =</strong></font> </p>
<p><font face="Courier New"><strong>reverse(reverse(y1s)++reverse(y2s) ++ &#8230;</strong></font> </p>
<p><font face="Courier New"><strong>        &#8230;    ++ reverse(yNs) )     ++xs</strong></font>                 <strong>(2)</strong> </p>
<p>  </p>
<p><font><strong>Remarkably</strong>, the argument of the outermost<font face="Courier New"> <strong><font size="3">reverse()</font></strong></font><font size="3"> </font>is a repetitive appends operation and it has only linear complexity with P1</font>! </p>
<p>We have added N+1 <font size="3"><font face="Courier New"><strong>reverse()</strong></font> </font>operations, but each of them is of linear complexity, so the total complexity of implementing <strong>(2)</strong> is O(N). </p>
<p>Certainly, the function <font face="Courier New" size="1"><strong>my:prepend-iter()</strong></font> we have demonstrated is a simplified case of the many different real world scenarios we may encounter that will require repetitive prepends. Nevertheless its use is sufficient to prove and demonstrate how such an O(N) algorithm can be constructed. </p>
<p>We could use essentially the same algorithm, with a modification that accepts as argument a function <br /><font face="Courier New" size="3"><strong>next-prepend()</strong></font>, which produces the next sequence to be prepended. To signal the end of the repetitive prepend operation, we can use a convention that <font face="Courier New" size="3"><strong>next-prepend()</strong></font> will indicate this by producing some special sequence, such as the empty sequence. </p>
<p>In case you may be wondering how can a function be passed as an argument to another function in XSLT, do read about <strong><a href="http://fxsl.sf.net/" target="_blank">FXSL</a></strong>.</p>
</p>
</p>
</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dnovatchev.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dnovatchev.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dnovatchev.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dnovatchev.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dnovatchev.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dnovatchev.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dnovatchev.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dnovatchev.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dnovatchev.wordpress.com&amp;blog=17873879&amp;post=10&amp;subd=dnovatchev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dnovatchev.wordpress.com/2008/12/24/optimized-repetitive-prepends-part-iii-understanding-the-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/23c32a15aa403737fbfb36135936047b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dnovatchev</media:title>
		</media:content>
	</item>
	</channel>
</rss>
