TheAlgorithms-C/df/d3c/threaded__binary__trees_8c.html
2020-06-28 20:40:24 +00:00

381 lines
30 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: data_structures/binary_trees/threaded_binary_trees.c File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C
&#160;<span id="projectnumber">1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('df/d3c/threaded__binary__trees_8c.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">threaded_binary_trees.c File Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>This file is a simple implementation of a Threaded Binary Tree.
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for threaded_binary_trees.c:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/df1/threaded__binary__trees_8c__incl.svg" width="166" height="142"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d8b/struct_node.html">Node</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight"><a class="el" href="../../db/d8b/struct_node.html" title="Node, the basic data structure of the tree.">Node</a>, the basic data structure of the tree. <a href="../../db/d8b/struct_node.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:ad8ecdcce462dd8e170ae1f164935aaa6"><td class="memItemLeft" align="right" valign="top"><a id="ad8ecdcce462dd8e170ae1f164935aaa6"></a>
typedef struct <a class="el" href="../../db/d8b/struct_node.html">Node</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#ad8ecdcce462dd8e170ae1f164935aaa6">node</a></td></tr>
<tr class="memdesc:ad8ecdcce462dd8e170ae1f164935aaa6"><td class="mdescLeft">&#160;</td><td class="mdescRight"><a class="el" href="../../db/d8b/struct_node.html" title="Node, the basic data structure of the tree.">Node</a>, the basic data structure of the tree. <br /></td></tr>
<tr class="separator:ad8ecdcce462dd8e170ae1f164935aaa6"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ab21d1d36d95001defbca2f6abd4d410c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d5/da1/structnode.html">node</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#ab21d1d36d95001defbca2f6abd4d410c">create_node</a> (int <a class="el" href="../../df/dea/structdata.html">data</a>)</td></tr>
<tr class="memdesc:ab21d1d36d95001defbca2f6abd4d410c"><td class="mdescLeft">&#160;</td><td class="mdescRight">creates a new node param[in] data value to be inserted <a href="../../df/d3c/threaded__binary__trees_8c.html#ab21d1d36d95001defbca2f6abd4d410c">More...</a><br /></td></tr>
<tr class="separator:ab21d1d36d95001defbca2f6abd4d410c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a823432888332fc9f0aa6072cff28c3bb"><td class="memItemLeft" align="right" valign="top"><a id="a823432888332fc9f0aa6072cff28c3bb"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#a823432888332fc9f0aa6072cff28c3bb">insert_bt</a> (<a class="el" href="../../d5/da1/structnode.html">node</a> **root, int <a class="el" href="../../df/dea/structdata.html">data</a>)</td></tr>
<tr class="memdesc:a823432888332fc9f0aa6072cff28c3bb"><td class="mdescLeft">&#160;</td><td class="mdescRight">inserts a node into the tree param[in,out] root pointer to node pointer to the topmost node of the tree param[in] data value to be inserted into the tree <br /></td></tr>
<tr class="separator:a823432888332fc9f0aa6072cff28c3bb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a306d567466f22e1e927aaed97d8bb58c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#a306d567466f22e1e927aaed97d8bb58c">search</a> (<a class="el" href="../../d5/da1/structnode.html">node</a> *root, int ele)</td></tr>
<tr class="memdesc:a306d567466f22e1e927aaed97d8bb58c"><td class="mdescLeft">&#160;</td><td class="mdescRight">searches for the element <a href="../../df/d3c/threaded__binary__trees_8c.html#a306d567466f22e1e927aaed97d8bb58c">More...</a><br /></td></tr>
<tr class="separator:a306d567466f22e1e927aaed97d8bb58c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4c1e06b5f0876ec9c1bd6817f3b7eda7"><td class="memItemLeft" align="right" valign="top"><a id="a4c1e06b5f0876ec9c1bd6817f3b7eda7"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#a4c1e06b5f0876ec9c1bd6817f3b7eda7">inorder_display</a> (<a class="el" href="../../d5/da1/structnode.html">node</a> *curr)</td></tr>
<tr class="memdesc:a4c1e06b5f0876ec9c1bd6817f3b7eda7"><td class="mdescLeft">&#160;</td><td class="mdescRight">performs inorder traversal param[in] curr node pointer to the topmost node of the tree <br /></td></tr>
<tr class="separator:a4c1e06b5f0876ec9c1bd6817f3b7eda7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5a82ae0ee13788be51ca4ba6cddb0719"><td class="memItemLeft" align="right" valign="top"><a id="a5a82ae0ee13788be51ca4ba6cddb0719"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#a5a82ae0ee13788be51ca4ba6cddb0719">postorder_display</a> (<a class="el" href="../../d5/da1/structnode.html">node</a> *curr)</td></tr>
<tr class="memdesc:a5a82ae0ee13788be51ca4ba6cddb0719"><td class="mdescLeft">&#160;</td><td class="mdescRight">performs postorder traversal param[in] curr node pointer to the topmost node of the tree <br /></td></tr>
<tr class="separator:a5a82ae0ee13788be51ca4ba6cddb0719"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8169ba0dfd5b8183672e444d1434bf9c"><td class="memItemLeft" align="right" valign="top"><a id="a8169ba0dfd5b8183672e444d1434bf9c"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#a8169ba0dfd5b8183672e444d1434bf9c">preorder_display</a> (<a class="el" href="../../d5/da1/structnode.html">node</a> *curr)</td></tr>
<tr class="memdesc:a8169ba0dfd5b8183672e444d1434bf9c"><td class="mdescLeft">&#160;</td><td class="mdescRight">performs preorder traversal param[in] curr node pointer to the topmost node of the tree <br /></td></tr>
<tr class="separator:a8169ba0dfd5b8183672e444d1434bf9c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a284d683f74b6c884e79ba00d3d1c3317"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#a284d683f74b6c884e79ba00d3d1c3317">delete_bt</a> (<a class="el" href="../../d5/da1/structnode.html">node</a> **root, int ele)</td></tr>
<tr class="memdesc:a284d683f74b6c884e79ba00d3d1c3317"><td class="mdescLeft">&#160;</td><td class="mdescRight">deletion of a node from the tree if the node isn't present in the tree, it takes no action. <a href="../../df/d3c/threaded__binary__trees_8c.html#a284d683f74b6c884e79ba00d3d1c3317">More...</a><br /></td></tr>
<tr class="separator:a284d683f74b6c884e79ba00d3d1c3317"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top"><a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">main function <br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>This file is a simple implementation of a Threaded Binary Tree. </p>
<p>Threaded Binary Tree is a binary tree variant in which all left child pointers that are NULL (in Linked list representation) point to its in-order predecessor, and all right child pointers that are NULL (in Linked list representation) point to its in-order successor. It has the following functionalities:</p><ul>
<li>Insertion</li>
<li>Search</li>
<li>Deletion</li>
<li>Listing of node keys inorder,preorder,postorder</li>
</ul>
<p>-see binary_search_tree.c</p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/amitnayakblr">Amitha Nayak</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ab21d1d36d95001defbca2f6abd4d410c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab21d1d36d95001defbca2f6abd4d410c">&#9670;&nbsp;</a></span>create_node()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="../../d5/da1/structnode.html">node</a>* create_node </td>
<td>(</td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>data</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>creates a new node param[in] data value to be inserted </p>
<dl class="section return"><dt>Returns</dt><dd>a pointer to the new node </dd></dl>
<div class="fragment"><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;{</div>
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160; <a class="code" href="../../d5/da1/structnode.html">node</a> *ptr = (<a class="code" href="../../d5/da1/structnode.html">node</a> *)malloc(<span class="keyword">sizeof</span>(<a class="code" href="../../d5/da1/structnode.html">node</a>));</div>
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160; ptr-&gt;rlink = ptr-&gt;llink = NULL;</div>
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; ptr-&gt;data = <a class="code" href="../../df/dea/structdata.html">data</a>;</div>
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; <span class="keywordflow">return</span> ptr;</div>
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a284d683f74b6c884e79ba00d3d1c3317"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a284d683f74b6c884e79ba00d3d1c3317">&#9670;&nbsp;</a></span>delete_bt()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void delete_bt </td>
<td>(</td>
<td class="paramtype"><a class="el" href="../../d5/da1/structnode.html">node</a> **&#160;</td>
<td class="paramname"><em>root</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>ele</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>deletion of a node from the tree if the node isn't present in the tree, it takes no action. </p>
<p>param[in,out] root pointer to node pointer to the topmost node of the tree param[in] ele value to be deleted from the tree </p>
<div class="fragment"><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>&#160;{</div>
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>&#160; <a class="code" href="../../d5/da1/structnode.html">node</a> *temp;</div>
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>&#160; <a class="code" href="../../d5/da1/structnode.html">node</a> *prev;</div>
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>&#160; <span class="keywordflow">if</span> (*root == NULL)</div>
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>&#160; <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; {</div>
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160; temp = *root;</div>
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160; prev = NULL;</div>
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160; <span class="comment">// search</span></div>
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160; <span class="keywordflow">while</span> (temp != NULL)</div>
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>&#160; {</div>
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160; <span class="keywordflow">if</span> (temp-&gt;data == ele)</div>
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160; {</div>
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160; <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>&#160; }</div>
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>&#160; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ele &gt; temp-&gt;data)</div>
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>&#160; {</div>
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>&#160; prev = temp;</div>
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>&#160; temp = temp-&gt;rlink;</div>
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>&#160; }</div>
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160; {</div>
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>&#160; prev = temp;</div>
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>&#160; temp = temp-&gt;llink;</div>
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>&#160; }</div>
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span>&#160; }</div>
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span>&#160; }</div>
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>&#160; </div>
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span>&#160; <span class="keywordflow">if</span> (temp == NULL)</div>
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>&#160; <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00206"></a><span class="lineno"> 206</span>&#160; {</div>
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>&#160; <a class="code" href="../../d5/da1/structnode.html">node</a> *replacement; <span class="comment">// deleted node&#39;s replacement</span></div>
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>&#160; <a class="code" href="../../d5/da1/structnode.html">node</a> *t;</div>
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>&#160; <span class="keywordflow">if</span> (temp-&gt;llink == NULL &amp;&amp; temp-&gt;rlink == NULL)</div>
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>&#160; {</div>
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>&#160; replacement = NULL;</div>
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>&#160; }</div>
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>&#160; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (temp-&gt;llink == NULL &amp;&amp; temp-&gt;rlink != NULL)</div>
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>&#160; {</div>
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>&#160; replacement = temp-&gt;rlink;</div>
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>&#160; }</div>
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>&#160; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (temp-&gt;llink != NULL &amp;&amp; temp-&gt;rlink == NULL)</div>
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>&#160; {</div>
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>&#160; replacement = temp-&gt;llink;</div>
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>&#160; }</div>
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>&#160; {</div>
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>&#160; replacement = temp-&gt;rlink; <span class="comment">// replaced with inorder successor</span></div>
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>&#160; t = replacement;</div>
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>&#160; <span class="keywordflow">while</span> (t-&gt;llink != NULL)</div>
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>&#160; {</div>
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>&#160; t = t-&gt;llink;</div>
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>&#160; }</div>
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>&#160; t-&gt;llink =</div>
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>&#160; temp-&gt;llink; <span class="comment">// leftmost node of the replacement is linked to</span></div>
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>&#160; <span class="comment">// the left child of the deleted node</span></div>
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>&#160; }</div>
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>&#160; </div>
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span>&#160; <span class="keywordflow">if</span> (temp == *root)</div>
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>&#160; {</div>
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span>&#160; free(*root);</div>
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>&#160; *root = replacement;</div>
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>&#160; }</div>
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>&#160; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prev-&gt;llink == temp)</div>
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>&#160; {</div>
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>&#160; free(prev-&gt;llink);</div>
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>&#160; prev-&gt;llink = replacement;</div>
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>&#160; }</div>
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>&#160; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prev-&gt;rlink == temp)</div>
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>&#160; {</div>
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>&#160; free(prev-&gt;rlink);</div>
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>&#160; prev-&gt;rlink = replacement;</div>
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span>&#160; }</div>
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span>&#160; }</div>
<div class="line"><a name="l00250"></a><span class="lineno"> 250</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a306d567466f22e1e927aaed97d8bb58c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a306d567466f22e1e927aaed97d8bb58c">&#9670;&nbsp;</a></span>search()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void search </td>
<td>(</td>
<td class="paramtype"><a class="el" href="../../d5/da1/structnode.html">node</a> *&#160;</td>
<td class="paramname"><em>root</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>ele</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>searches for the element </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">root</td><td>node pointer to the topmost node of the tree </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">ele</td><td>value searched for </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160;{</div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; <a class="code" href="../../d5/da1/structnode.html">node</a> *temp = root;</div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; <span class="keywordflow">while</span> (temp != NULL)</div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; {</div>
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; <span class="keywordflow">if</span> (temp-&gt;data == ele)</div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; {</div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; }</div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ele &gt; temp-&gt;data)</div>
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160; {</div>
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160; temp = temp-&gt;rlink;</div>
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160; }</div>
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160; {</div>
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; temp = temp-&gt;llink;</div>
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; }</div>
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160; }</div>
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>&#160; </div>
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>&#160; <span class="keywordflow">if</span> (temp == NULL)</div>
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>&#160; {</div>
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>&#160; printf(<span class="stringliteral">&quot;%s\n&quot;</span>, <span class="stringliteral">&quot;Element not found.&quot;</span>);</div>
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>&#160; }</div>
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span>&#160; printf(<span class="stringliteral">&quot;%s\n&quot;</span>, <span class="stringliteral">&quot;Element found.&quot;</span>);</div>
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="astructdata_html"><div class="ttname"><a href="../../df/dea/structdata.html">data</a></div><div class="ttdef"><b>Definition:</b> prime_factoriziation.c:25</div></div>
<div class="ttc" id="astructnode_html"><div class="ttname"><a href="../../d5/da1/structnode.html">node</a></div><div class="ttdoc">Kyler Smith, 2017 Stack data structure implementation.</div><div class="ttdef"><b>Definition:</b> binary_search_tree.c:14</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html">data_structures</a></li><li class="navelem"><a class="el" href="../../dir_e39df94f82619fa5256f1786519937be.html">binary_trees</a></li><li class="navelem"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html">threaded_binary_trees.c</a></li>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.18 </li>
</ul>
</div>
</body>
</html>