mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
610 lines
51 KiB
HTML
610 lines
51 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
|
|
 <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&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&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&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> |
|
|
<a href="#typedef-members">Typedefs</a> |
|
|
<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 <stdio.h></code><br />
|
|
<code>#include <stdlib.h></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  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d8b/struct_node.html">Node</a></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </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">typedef struct <a class="el" href="../../db/d8b/struct_node.html">Node</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#ad8ecdcce462dd8e170ae1f164935aaa6">node</a></td></tr>
|
|
<tr class="separator:ad8ecdcce462dd8e170ae1f164935aaa6"><td class="memSeparator" colspan="2"> </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> * </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="separator:ab21d1d36d95001defbca2f6abd4d410c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a823432888332fc9f0aa6072cff28c3bb"><td class="memItemLeft" align="right" valign="top">void </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="separator:a823432888332fc9f0aa6072cff28c3bb"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a306d567466f22e1e927aaed97d8bb58c"><td class="memItemLeft" align="right" valign="top">void </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="separator:a306d567466f22e1e927aaed97d8bb58c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a4c1e06b5f0876ec9c1bd6817f3b7eda7"><td class="memItemLeft" align="right" valign="top">void </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="separator:a4c1e06b5f0876ec9c1bd6817f3b7eda7"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a5a82ae0ee13788be51ca4ba6cddb0719"><td class="memItemLeft" align="right" valign="top">void </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="separator:a5a82ae0ee13788be51ca4ba6cddb0719"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a8169ba0dfd5b8183672e444d1434bf9c"><td class="memItemLeft" align="right" valign="top">void </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="separator:a8169ba0dfd5b8183672e444d1434bf9c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a284d683f74b6c884e79ba00d3d1c3317"><td class="memItemLeft" align="right" valign="top">void </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="separator:a284d683f74b6c884e79ba00d3d1c3317"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d3c/threaded__binary__trees_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </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">Typedef Documentation</h2>
|
|
<a id="ad8ecdcce462dd8e170ae1f164935aaa6"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ad8ecdcce462dd8e170ae1f164935aaa6">◆ </a></span>node</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">typedef struct <a class="el" href="../../db/d8b/struct_node.html">Node</a> <a class="el" href="../../d5/da1/structnode.html">node</a></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<p><a class="el" href="../../db/d8b/struct_node.html">Node</a>, the basic data structure of the tree </p>
|
|
|
|
</div>
|
|
</div>
|
|
<h2 class="groupheader">Function Documentation</h2>
|
|
<a id="ab21d1d36d95001defbca2f6abd4d410c"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ab21d1d36d95001defbca2f6abd4d410c">◆ </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 </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> {</div>
|
|
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  <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>  ptr->rlink = ptr->llink = NULL;</div>
|
|
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  ptr->data = <a class="code" href="../../df/dea/structdata.html">data</a>;</div>
|
|
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="keywordflow">return</span> ptr;</div>
|
|
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a284d683f74b6c884e79ba00d3d1c3317"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a284d683f74b6c884e79ba00d3d1c3317">◆ </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> ** </td>
|
|
<td class="paramname"><em>root</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>ele</em> </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. 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> {</div>
|
|
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *temp;</div>
|
|
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *prev;</div>
|
|
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  <span class="keywordflow">if</span> (*root == NULL)</div>
|
|
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  {</div>
|
|
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  temp = *root;</div>
|
|
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  prev = NULL;</div>
|
|
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  <span class="comment">// search</span></div>
|
|
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  <span class="keywordflow">while</span> (temp != NULL)</div>
|
|
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  {</div>
|
|
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  <span class="keywordflow">if</span> (temp->data == ele)</div>
|
|
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  {</div>
|
|
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  }</div>
|
|
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ele > temp->data)</div>
|
|
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  {</div>
|
|
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  prev = temp;</div>
|
|
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  temp = temp->rlink;</div>
|
|
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  }</div>
|
|
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  {</div>
|
|
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  prev = temp;</div>
|
|
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  temp = temp->llink;</div>
|
|
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  }</div>
|
|
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  }</div>
|
|
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  }</div>
|
|
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  </div>
|
|
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  <span class="keywordflow">if</span> (temp == NULL)</div>
|
|
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  {</div>
|
|
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *replacement; <span class="comment">// deleted node's replacement</span></div>
|
|
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *t;</div>
|
|
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  <span class="keywordflow">if</span> (temp->llink == NULL && temp->rlink == NULL)</div>
|
|
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  {</div>
|
|
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  replacement = NULL;</div>
|
|
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  }</div>
|
|
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (temp->llink == NULL && temp->rlink != NULL)</div>
|
|
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  {</div>
|
|
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  replacement = temp->rlink;</div>
|
|
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  }</div>
|
|
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (temp->llink != NULL && temp->rlink == NULL)</div>
|
|
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  {</div>
|
|
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  replacement = temp->llink;</div>
|
|
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  }</div>
|
|
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  {</div>
|
|
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  replacement = temp->rlink; <span class="comment">// replaced with inorder successor</span></div>
|
|
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  t = replacement;</div>
|
|
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  <span class="keywordflow">while</span> (t->llink != NULL)</div>
|
|
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  {</div>
|
|
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>  t = t->llink;</div>
|
|
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>  }</div>
|
|
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>  t->llink =</div>
|
|
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>  temp->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>  <span class="comment">// the left child of the deleted node</span></div>
|
|
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  }</div>
|
|
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  </div>
|
|
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span>  <span class="keywordflow">if</span> (temp == *root)</div>
|
|
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  {</div>
|
|
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span>  free(*root);</div>
|
|
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  *root = replacement;</div>
|
|
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  }</div>
|
|
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prev->llink == temp)</div>
|
|
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  {</div>
|
|
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  free(prev->llink);</div>
|
|
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  prev->llink = replacement;</div>
|
|
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>  }</div>
|
|
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prev->rlink == temp)</div>
|
|
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>  {</div>
|
|
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  free(prev->rlink);</div>
|
|
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  prev->rlink = replacement;</div>
|
|
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span>  }</div>
|
|
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  }</div>
|
|
<div class="line"><a name="l00250"></a><span class="lineno"> 250</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a4c1e06b5f0876ec9c1bd6817f3b7eda7"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a4c1e06b5f0876ec9c1bd6817f3b7eda7">◆ </a></span>inorder_display()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void inorder_display </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../d5/da1/structnode.html">node</a> * </td>
|
|
<td class="paramname"><em>curr</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<p>performs inorder traversal param[in] curr node pointer to the topmost node of the tree </p>
|
|
<div class="fragment"><div class="line"><a name="l00130"></a><span class="lineno"> 130</span> {</div>
|
|
<div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="keywordflow">if</span> (curr != NULL)</div>
|
|
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  {</div>
|
|
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a4c1e06b5f0876ec9c1bd6817f3b7eda7">inorder_display</a>(curr->llink);</div>
|
|
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  printf(<span class="stringliteral">"%d\t"</span>, curr->data);</div>
|
|
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a4c1e06b5f0876ec9c1bd6817f3b7eda7">inorder_display</a>(curr->rlink);</div>
|
|
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  }</div>
|
|
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a823432888332fc9f0aa6072cff28c3bb"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a823432888332fc9f0aa6072cff28c3bb">◆ </a></span>insert_bt()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void insert_bt </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../d5/da1/structnode.html">node</a> ** </td>
|
|
<td class="paramname"><em>root</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>data</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<p>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 </p>
|
|
<div class="fragment"><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> {</div>
|
|
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *new_node = <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#ab21d1d36d95001defbca2f6abd4d410c">create_node</a>(<a class="code" href="../../df/dea/structdata.html">data</a>);</div>
|
|
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *temp; <span class="comment">// to be deleted</span></div>
|
|
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *prev; <span class="comment">// keeps track of the parent of the element deleted</span></div>
|
|
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="keywordflow">if</span> (*root == NULL)</div>
|
|
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  {</div>
|
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  *root = new_node;</div>
|
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  }</div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  {</div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  temp = *root;</div>
|
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  prev = NULL;</div>
|
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="keywordflow">while</span> (temp != NULL)</div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  {</div>
|
|
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <span class="keywordflow">if</span> (new_node->data > temp->data)</div>
|
|
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  {</div>
|
|
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  prev = temp;</div>
|
|
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  temp = temp->rlink;</div>
|
|
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  }</div>
|
|
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (new_node->data < temp->data)</div>
|
|
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  {</div>
|
|
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  prev = temp;</div>
|
|
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  temp = temp->llink;</div>
|
|
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  }</div>
|
|
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  {</div>
|
|
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  }</div>
|
|
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  }</div>
|
|
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  </div>
|
|
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <span class="keywordflow">if</span> (new_node->data > prev->data)</div>
|
|
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  {</div>
|
|
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  prev->rlink = new_node;</div>
|
|
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  }</div>
|
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  {</div>
|
|
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  prev->llink = new_node;</div>
|
|
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  }</div>
|
|
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  }</div>
|
|
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span> }</div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d3c/threaded__binary__trees_8c_a823432888332fc9f0aa6072cff28c3bb_cgraph.svg" width="224" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<p>main function </p>
|
|
<div class="fragment"><div class="line"><a name="l00256"></a><span class="lineno"> 256</span> {</div>
|
|
<div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  printf(<span class="stringliteral">"BINARY THREADED TREE: \n"</span>);</div>
|
|
<div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  <a class="code" href="../../d5/da1/structnode.html">node</a> *root = NULL;</div>
|
|
<div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  <span class="keywordtype">int</span> choice, n;</div>
|
|
<div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  <span class="keywordflow">do</span></div>
|
|
<div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  {</div>
|
|
<div class="line"><a name="l00262"></a><span class="lineno"> 262</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"1. Insert into BT"</span>);</div>
|
|
<div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"2. Print BT - inorder"</span>);</div>
|
|
<div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"3. Print BT - preorder"</span>);</div>
|
|
<div class="line"><a name="l00265"></a><span class="lineno"> 265</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"4. print BT - postorder"</span>);</div>
|
|
<div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"5. delete from BT"</span>);</div>
|
|
<div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"6. search in BT"</span>);</div>
|
|
<div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"Type 0 to exit"</span>);</div>
|
|
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  scanf(<span class="stringliteral">"%d"</span>, &choice);</div>
|
|
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  </div>
|
|
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  <span class="keywordflow">switch</span> (choice)</div>
|
|
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  {</div>
|
|
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  <span class="keywordflow">case</span> 1:</div>
|
|
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"Enter a no:"</span>);</div>
|
|
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  scanf(<span class="stringliteral">"%d"</span>, &n);</div>
|
|
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a823432888332fc9f0aa6072cff28c3bb">insert_bt</a>(&root, n);</div>
|
|
<div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  <span class="keywordflow">case</span> 2:</div>
|
|
<div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a4c1e06b5f0876ec9c1bd6817f3b7eda7">inorder_display</a>(root);</div>
|
|
<div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  printf(<span class="stringliteral">"\n"</span>);</div>
|
|
<div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  <span class="keywordflow">case</span> 3:</div>
|
|
<div class="line"><a name="l00283"></a><span class="lineno"> 283</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a8169ba0dfd5b8183672e444d1434bf9c">preorder_display</a>(root);</div>
|
|
<div class="line"><a name="l00284"></a><span class="lineno"> 284</span>  printf(<span class="stringliteral">"\n"</span>);</div>
|
|
<div class="line"><a name="l00285"></a><span class="lineno"> 285</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  <span class="keywordflow">case</span> 4:</div>
|
|
<div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a5a82ae0ee13788be51ca4ba6cddb0719">postorder_display</a>(root);</div>
|
|
<div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  printf(<span class="stringliteral">"\n"</span>);</div>
|
|
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00290"></a><span class="lineno"> 290</span>  <span class="keywordflow">case</span> 5:</div>
|
|
<div class="line"><a name="l00291"></a><span class="lineno"> 291</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"Enter a no:"</span>);</div>
|
|
<div class="line"><a name="l00292"></a><span class="lineno"> 292</span>  scanf(<span class="stringliteral">"%d"</span>, &n);</div>
|
|
<div class="line"><a name="l00293"></a><span class="lineno"> 293</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a284d683f74b6c884e79ba00d3d1c3317">delete_bt</a>(&root, n);</div>
|
|
<div class="line"><a name="l00294"></a><span class="lineno"> 294</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00295"></a><span class="lineno"> 295</span>  <span class="keywordflow">case</span> 6:</div>
|
|
<div class="line"><a name="l00296"></a><span class="lineno"> 296</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"Enter a no:"</span>);</div>
|
|
<div class="line"><a name="l00297"></a><span class="lineno"> 297</span>  scanf(<span class="stringliteral">"%d"</span>, &n);</div>
|
|
<div class="line"><a name="l00298"></a><span class="lineno"> 298</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a306d567466f22e1e927aaed97d8bb58c">search</a>(root, n);</div>
|
|
<div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00300"></a><span class="lineno"> 300</span>  }</div>
|
|
<div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  } <span class="keywordflow">while</span> (choice != 0);</div>
|
|
<div class="line"><a name="l00302"></a><span class="lineno"> 302</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00303"></a><span class="lineno"> 303</span> }</div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d3c/threaded__binary__trees_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="375" height="291"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a5a82ae0ee13788be51ca4ba6cddb0719"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a5a82ae0ee13788be51ca4ba6cddb0719">◆ </a></span>postorder_display()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void postorder_display </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../d5/da1/structnode.html">node</a> * </td>
|
|
<td class="paramname"><em>curr</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<p>performs postorder traversal param[in] curr node pointer to the topmost node of the tree </p>
|
|
<div class="fragment"><div class="line"><a name="l00144"></a><span class="lineno"> 144</span> {</div>
|
|
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  <span class="keywordflow">if</span> (curr != NULL)</div>
|
|
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  {</div>
|
|
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a5a82ae0ee13788be51ca4ba6cddb0719">postorder_display</a>(curr->llink);</div>
|
|
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a5a82ae0ee13788be51ca4ba6cddb0719">postorder_display</a>(curr->rlink);</div>
|
|
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  printf(<span class="stringliteral">"%d\t"</span>, curr->data);</div>
|
|
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  }</div>
|
|
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a8169ba0dfd5b8183672e444d1434bf9c"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a8169ba0dfd5b8183672e444d1434bf9c">◆ </a></span>preorder_display()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void preorder_display </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../d5/da1/structnode.html">node</a> * </td>
|
|
<td class="paramname"><em>curr</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<p>performs preorder traversal param[in] curr node pointer to the topmost node of the tree </p>
|
|
<div class="fragment"><div class="line"><a name="l00158"></a><span class="lineno"> 158</span> {</div>
|
|
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  <span class="keywordflow">if</span> (curr != NULL)</div>
|
|
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  {</div>
|
|
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  printf(<span class="stringliteral">"%d\t"</span>, curr->data);</div>
|
|
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a8169ba0dfd5b8183672e444d1434bf9c">preorder_display</a>(curr->llink);</div>
|
|
<div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  <a class="code" href="../../df/d3c/threaded__binary__trees_8c.html#a8169ba0dfd5b8183672e444d1434bf9c">preorder_display</a>(curr->rlink);</div>
|
|
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  }</div>
|
|
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a306d567466f22e1e927aaed97d8bb58c"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a306d567466f22e1e927aaed97d8bb58c">◆ </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> * </td>
|
|
<td class="paramname"><em>root</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>ele</em> </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> {</div>
|
|
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <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>  <span class="keywordflow">while</span> (temp != NULL)</div>
|
|
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  {</div>
|
|
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">if</span> (temp->data == ele)</div>
|
|
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  {</div>
|
|
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  }</div>
|
|
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ele > temp->data)</div>
|
|
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  {</div>
|
|
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  temp = temp->rlink;</div>
|
|
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  }</div>
|
|
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  {</div>
|
|
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  temp = temp->llink;</div>
|
|
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  }</div>
|
|
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  }</div>
|
|
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  </div>
|
|
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="keywordflow">if</span> (temp == NULL)</div>
|
|
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  {</div>
|
|
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"Element not found."</span>);</div>
|
|
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  }</div>
|
|
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  printf(<span class="stringliteral">"%s\n"</span>, <span class="stringliteral">"Element found."</span>);</div>
|
|
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_a284d683f74b6c884e79ba00d3d1c3317"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#a284d683f74b6c884e79ba00d3d1c3317">delete_bt</a></div><div class="ttdeci">void delete_bt(node **root, int ele)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:173</div></div>
|
|
<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="ttdef"><b>Definition:</b> binary_search_tree.c:14</div></div>
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_a5a82ae0ee13788be51ca4ba6cddb0719"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#a5a82ae0ee13788be51ca4ba6cddb0719">postorder_display</a></div><div class="ttdeci">void postorder_display(node *curr)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:143</div></div>
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_a306d567466f22e1e927aaed97d8bb58c"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#a306d567466f22e1e927aaed97d8bb58c">search</a></div><div class="ttdeci">void search(node *root, int ele)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:98</div></div>
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_a8169ba0dfd5b8183672e444d1434bf9c"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#a8169ba0dfd5b8183672e444d1434bf9c">preorder_display</a></div><div class="ttdeci">void preorder_display(node *curr)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:157</div></div>
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_a4c1e06b5f0876ec9c1bd6817f3b7eda7"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#a4c1e06b5f0876ec9c1bd6817f3b7eda7">inorder_display</a></div><div class="ttdeci">void inorder_display(node *curr)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:129</div></div>
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_ab21d1d36d95001defbca2f6abd4d410c"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#ab21d1d36d95001defbca2f6abd4d410c">create_node</a></div><div class="ttdeci">node * create_node(int data)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:38</div></div>
|
|
<div class="ttc" id="athreaded__binary__trees_8c_html_a823432888332fc9f0aa6072cff28c3bb"><div class="ttname"><a href="../../df/d3c/threaded__binary__trees_8c.html#a823432888332fc9f0aa6072cff28c3bb">insert_bt</a></div><div class="ttdeci">void insert_bt(node **root, int data)</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:51</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>
|