<divclass="center"><iframescrolling="no"frameborder="0"src="../../d8/d1c/binary__search__tree_8c__incl.svg"width="198"height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<trclass="memdesc:"><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="../../db/d8b/struct_node.html"title="Node, the basic data structure of the tree.">Node</a>, the basic data structure in the tree. <ahref="../../d5/da1/structnode.html#details">More...</a><br/></td></tr>
<trclass="memdesc:af4aeda155dbe167f1c1cf38cb65bf324"><tdclass="mdescLeft"> </td><tdclass="mdescRight"><aclass="el"href="../../db/d8b/struct_node.html"title="Node, the basic data structure of the tree.">Node</a>, the basic data structure in the tree. <br/></td></tr>
<trclass="memdesc:adf2169c1008551b20c4a59fcf0c9ab3b"><tdclass="mdescLeft"> </td><tdclass="mdescRight">The node constructor, which receives the key value input and returns a node pointer. <ahref="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">More...</a><br/></td></tr>
<trclass="memitem:a031cc98830742bca57c0da81a0fb779f"><tdclass="memItemLeft"align="right"valign="top"><aclass="el"href="../../d5/da1/structnode.html">node</a> * </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../da/d02/binary__search__tree_8c.html#a031cc98830742bca57c0da81a0fb779f">insert</a> (<aclass="el"href="../../d5/da1/structnode.html">node</a> *root, int <aclass="el"href="../../df/dea/structdata.html">data</a>)</td></tr>
<trclass="memdesc:a031cc98830742bca57c0da81a0fb779f"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Insertion procedure, which inserts the input key in a new node in the tree. <ahref="../../da/d02/binary__search__tree_8c.html#a031cc98830742bca57c0da81a0fb779f">More...</a><br/></td></tr>
<trclass="memdesc:ad50f3debc5323bb7b71933effb64f30f"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Utilitary procedure to find the greatest key in the left subtree. <ahref="../../da/d02/binary__search__tree_8c.html#ad50f3debc5323bb7b71933effb64f30f">More...</a><br/></td></tr>
<trclass="memitem:a6983e8a91a3d25d7d000807f18ba2748"><tdclass="memItemLeft"align="right"valign="top"><aclass="el"href="../../d5/da1/structnode.html">node</a> * </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../da/d02/binary__search__tree_8c.html#a6983e8a91a3d25d7d000807f18ba2748">delete</a> (<aclass="el"href="../../d5/da1/structnode.html">node</a> *root, int <aclass="el"href="../../df/dea/structdata.html">data</a>)</td></tr>
<trclass="memdesc:a6983e8a91a3d25d7d000807f18ba2748"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Deletion procedure, which searches for the input key in the tree and removes it if present. <ahref="../../da/d02/binary__search__tree_8c.html#a6983e8a91a3d25d7d000807f18ba2748">More...</a><br/></td></tr>
<trclass="memitem:adff4c6248834a9944a1fb03a20230c9c"><tdclass="memItemLeft"align="right"valign="top">int </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../da/d02/binary__search__tree_8c.html#adff4c6248834a9944a1fb03a20230c9c">find</a> (<aclass="el"href="../../d5/da1/structnode.html">node</a> *root, int <aclass="el"href="../../df/dea/structdata.html">data</a>)</td></tr>
<trclass="memdesc:adff4c6248834a9944a1fb03a20230c9c"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Search procedure, which looks for the input key in the tree and returns 1 if it's present or 0 if it's not in the tree. <ahref="../../da/d02/binary__search__tree_8c.html#adff4c6248834a9944a1fb03a20230c9c">More...</a><br/></td></tr>
<trclass="memdesc:ae4a66d8b0c2b0d626aea45977e358c83"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Utilitary procedure to measure the height of the binary tree. <ahref="../../da/d02/binary__search__tree_8c.html#ae4a66d8b0c2b0d626aea45977e358c83">More...</a><br/></td></tr>
<trclass="memdesc:a01151353aa2d9688934ed39208133241"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Utilitary procedure to free all nodes in a tree. <ahref="../../da/d02/binary__search__tree_8c.html#a01151353aa2d9688934ed39208133241">More...</a><br/></td></tr>
<trclass="memdesc:a0f18adaaca5ecc410cfa16dd2a3684dc"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Traversal procedure to list the current keys in the tree in order of value (from the left to the right) <ahref="../../da/d02/binary__search__tree_8c.html#a0f18adaaca5ecc410cfa16dd2a3684dc">More...</a><br/></td></tr>
<divclass="line"><aid="l00090"name="l00090"></a><spanclass="lineno"> 90</span><spanclass="comment">// If the root is null, nothing to be done</span></div>
<divclass="line"><aid="l00096"name="l00096"></a><spanclass="lineno"> 96</span> { <spanclass="comment">// If the input key is greater than the root's, search in the right</span></div>
<divclass="line"><aid="l00101"name="l00101"></a><spanclass="lineno"> 101</span> { <spanclass="comment">// If the input key is lower than the root's, search in the left subtree</span></div>
<divclass="line"><aid="l00106"name="l00106"></a><spanclass="lineno"> 106</span><spanclass="comment">// If the input key matches the root's, check the following cases</span></div>
<divclass="line"><aid="l00109"name="l00109"></a><spanclass="lineno"> 109</span> { <spanclass="comment">// Case 1: the root has no leaves, remove the node</span></div>
<divclass="line"><aid="l00114"name="l00114"></a><spanclass="lineno"> 114</span> { <spanclass="comment">// Case 2: the root has one leaf, make the leaf the new root and</span></div>
<divclass="line"><aid="l00130"name="l00130"></a><spanclass="lineno"> 130</span> { <spanclass="comment">// Case 3: the root has 2 leaves, find the greatest key in the left</span></div>
<divclass="line"><aid="l00131"name="l00131"></a><spanclass="lineno"> 131</span><spanclass="comment">// subtree and switch with the root's</span></div>
<divclass="line"><aid="l00133"name="l00133"></a><spanclass="lineno"> 133</span><spanclass="comment">// finds the biggest node in the left branch.</span></div>
<divclass="line"><aid="l00136"name="l00136"></a><spanclass="lineno"> 136</span><spanclass="comment">// sets the data of this node equal to the data of the biggest node</span></div>
<divclass="ttc"id="abinary__search__tree_8c_html_ad50f3debc5323bb7b71933effb64f30f"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#ad50f3debc5323bb7b71933effb64f30f">getMax</a></div><divclass="ttdeci">node * getMax(node *root)</div><divclass="ttdoc">Utilitary procedure to find the greatest key in the left subtree.</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:72</div></div>
<divclass="ttc"id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><divclass="ttname"><ahref="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><divclass="ttdeci">#define free(ptr)</div><divclass="ttdoc">This macro replace the standard free function with free_dbg.</div><divclass="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
<divclass="ttc"id="astructnode_html"><divclass="ttname"><ahref="../../d5/da1/structnode.html">node</a></div><divclass="ttdoc">Node, the basic data structure in the tree.</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:15</div></div>
<divclass="ttc"id="astructnode_html_a2d890bb9f6af0ffd73fe79b21124c2a2"><divclass="ttname"><ahref="../../d5/da1/structnode.html#a2d890bb9f6af0ffd73fe79b21124c2a2">node::data</a></div><divclass="ttdeci">int data</div><divclass="ttdoc">data of the node</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:18</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_a6983e8a91a3d25d7d000807f18ba2748_cgraph.svg"width="183"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aid="l00154"name="l00154"></a><spanclass="lineno"> 154</span><spanclass="comment">// If the root is null, the key's not present</span></div>
<divclass="line"><aid="l00161"name="l00161"></a><spanclass="lineno"> 161</span><spanclass="comment">// If the input key is greater than the root's, search in the right</span></div>
<divclass="line"><aid="l00167"name="l00167"></a><spanclass="lineno"> 167</span><spanclass="comment">// If the input key is lower than the root's, search in the left subtree</span></div>
<divclass="line"><aid="l00172"name="l00172"></a><spanclass="lineno"> 172</span><spanclass="comment">// If the input and the root key match, return 1</span></div>
<divclass="ttc"id="abinary__search__tree_8c_html_adff4c6248834a9944a1fb03a20230c9c"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#adff4c6248834a9944a1fb03a20230c9c">find</a></div><divclass="ttdeci">int find(node *root, int data)</div><divclass="ttdoc">Search procedure, which looks for the input key in the tree and returns 1 if it's present or 0 if it'...</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:152</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_adff4c6248834a9944a1fb03a20230c9c_cgraph.svg"width="55"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aid="l00074"name="l00074"></a><spanclass="lineno"> 74</span><spanclass="comment">// If there's no leaf to the right, then this is the maximum key value</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_ad50f3debc5323bb7b71933effb64f30f_cgraph.svg"width="76"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aid="l00189"name="l00189"></a><spanclass="lineno"> 189</span><spanclass="comment">// If the root is null, this is the bottom of the tree (height 0)</span></div>
<divclass="line"><aid="l00196"name="l00196"></a><spanclass="lineno"> 196</span><spanclass="comment">// Get the height from both left and right subtrees to check which is</span></div>
<divclass="line"><aid="l00197"name="l00197"></a><spanclass="lineno"> 197</span><spanclass="comment">// the greatest</span></div>
<divclass="line"><aid="l00201"name="l00201"></a><spanclass="lineno"> 201</span><spanclass="comment">// The final height is the height of the greatest subtree(left or right)</span></div>
<divclass="line"><aid="l00202"name="l00202"></a><spanclass="lineno"> 202</span><spanclass="comment">// plus 1(which is the root's level)</span></div>
<divclass="ttc"id="abinary__search__tree_8c_html_ae4a66d8b0c2b0d626aea45977e358c83"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#ae4a66d8b0c2b0d626aea45977e358c83">height</a></div><divclass="ttdeci">int height(node *root)</div><divclass="ttdoc">Utilitary procedure to measure the height of the binary tree.</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:187</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_ae4a66d8b0c2b0d626aea45977e358c83_cgraph.svg"width="70"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="ttc"id="abinary__search__tree_8c_html_a0f18adaaca5ecc410cfa16dd2a3684dc"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#a0f18adaaca5ecc410cfa16dd2a3684dc">inOrder</a></div><divclass="ttdeci">void inOrder(node *root)</div><divclass="ttdoc">Traversal procedure to list the current keys in the tree in order of value (from the left to the righ...</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:238</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_a0f18adaaca5ecc410cfa16dd2a3684dc_cgraph.svg"width="78"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aid="l00048"name="l00048"></a><spanclass="lineno"> 48</span><spanclass="comment">// If the root of the subtree is null, insert key here</span></div>
<divclass="line"><aid="l00055"name="l00055"></a><spanclass="lineno"> 55</span><spanclass="comment">// If it isn't null and the input key is greater than the root key,</span></div>
<divclass="line"><aid="l00056"name="l00056"></a><spanclass="lineno"> 56</span><spanclass="comment">// insert in the right leaf</span></div>
<divclass="line"><aid="l00060"name="l00060"></a><spanclass="lineno"> 60</span> { <spanclass="comment">// If it isn't null and the input key is lower than the root key, insert</span></div>
<divclass="line"><aid="l00061"name="l00061"></a><spanclass="lineno"> 61</span><spanclass="comment">// in the left leaf</span></div>
<divclass="ttc"id="abinary__search__tree_8c_html_a031cc98830742bca57c0da81a0fb779f"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#a031cc98830742bca57c0da81a0fb779f">insert</a></div><divclass="ttdeci">node * insert(node *root, int data)</div><divclass="ttdoc">Insertion procedure, which inserts the input key in a new node in the tree.</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:46</div></div>
<divclass="ttc"id="abinary__search__tree_8c_html_adf2169c1008551b20c4a59fcf0c9ab3b"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a></div><divclass="ttdeci">node * newNode(int data)</div><divclass="ttdoc">The node constructor, which receives the key value input and returns a node pointer.</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:28</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_a031cc98830742bca57c0da81a0fb779f_cgraph.svg"width="192"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aid="l00261"name="l00261"></a><spanclass="lineno"> 261</span><spanclass="stringliteral">"\n\n[1] Insert Node\n[2] Delete Node\n[3] Find a Node\n[4] Get "</span></div>
<divclass="line"><aid="l00262"name="l00262"></a><spanclass="lineno"> 262</span><spanclass="stringliteral">"current Height\n[5] Print Tree in Crescent Order\n[0] Quit\n"</span>);</div>
<divclass="line"><aid="l00263"name="l00263"></a><spanclass="lineno"> 263</span> scanf(<spanclass="stringliteral">"%d"</span>, &opt); <spanclass="comment">// reads the choice of the user</span></div>
<divclass="line"><aid="l00269"name="l00269"></a><spanclass="lineno"> 269</span> printf(<spanclass="stringliteral">"Enter the new node's value:\n"</span>);</div>
<divclass="line"><aid="l00275"name="l00275"></a><spanclass="lineno"> 275</span> printf(<spanclass="stringliteral">"Enter the value to be removed:\n"</span>);</div>
<divclass="line"><aid="l00290"name="l00290"></a><spanclass="lineno"> 290</span><aclass="code hl_function"href="../../da/d02/binary__search__tree_8c.html#adff4c6248834a9944a1fb03a20230c9c">find</a>(root, <aclass="code hl_struct"href="../../df/dea/structdata.html">data</a>) ? printf(<spanclass="stringliteral">"The value is in the tree.\n"</span>)</div>
<divclass="line"><aid="l00291"name="l00291"></a><spanclass="lineno"> 291</span> : printf(<spanclass="stringliteral">"The value is not in the tree.\n"</span>);</div>
<divclass="line"><aid="l00295"name="l00295"></a><spanclass="lineno"> 295</span> printf(<spanclass="stringliteral">"Current height of the tree is: %d\n"</span>, <aclass="code hl_function"href="../../da/d02/binary__search__tree_8c.html#ae4a66d8b0c2b0d626aea45977e358c83">height</a>(root));</div>
<divclass="ttc"id="abinary__search__tree_8c_html_a01151353aa2d9688934ed39208133241"><divclass="ttname"><ahref="../../da/d02/binary__search__tree_8c.html#a01151353aa2d9688934ed39208133241">purge</a></div><divclass="ttdeci">void purge(node *root)</div><divclass="ttdoc">Utilitary procedure to free all nodes in a tree.</div><divclass="ttdef"><b>Definition:</b> binary_search_tree.c:217</div></div>
</div><!-- fragment --><divclass="dynheader">
Here is the call graph for this function:</div>
<divclass="dyncontent">
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg"width="303"height="360"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="ttc"id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><divclass="ttname"><ahref="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><divclass="ttdeci">#define malloc(bytes)</div><divclass="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><divclass="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d02/binary__search__tree_8c_a01151353aa2d9688934ed39208133241_cgraph.svg"width="67"height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<liclass="footer">Generated by <ahref="https://www.doxygen.org/index.html"><imgclass="footer"src="../../doxygen.svg"width="104"height="31"alt="doxygen"/></a> 1.9.2 </li>