mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-02 18:17:02 +03:00
700 lines
56 KiB
HTML
700 lines
56 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" lang="en-US">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||
|
<meta name="generator" content="Doxygen 1.9.6"/>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||
|
<title>Algorithms_in_C: data_structures/stack/dynamic_stack.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 id="projectrow">
|
||
|
<td id="projectalign">
|
||
|
<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.9.6 -->
|
||
|
<script type="text/javascript">
|
||
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||
|
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||
|
/* @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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||
|
$(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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||
|
$(document).ready(function(){initNavTree('d5/d24/dynamic__stack_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">
|
||
|
<div id="MSearchResults">
|
||
|
<div class="SRPage">
|
||
|
<div id="SRIndex">
|
||
|
<div id="SRResults"></div>
|
||
|
<div class="SRStatus" id="Loading">Loading...</div>
|
||
|
<div class="SRStatus" id="Searching">Searching...</div>
|
||
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</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">dynamic_stack.c File Reference</div></div>
|
||
|
</div><!--header-->
|
||
|
<div class="contents">
|
||
|
|
||
|
<p>Dynamic <a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)" target="_blank">Stack</a>, just like Dynamic Array, is a stack data structure whose the length or capacity (maximum number of elements that can be stored) increases or decreases in real time based on the operations (like insertion or deletion) performed on it.
|
||
|
<a href="#details">More...</a></p>
|
||
|
<div class="textblock"><code>#include <assert.h></code><br />
|
||
|
<code>#include <inttypes.h></code><br />
|
||
|
<code>#include <stdio.h></code><br />
|
||
|
<code>#include <stdlib.h></code><br />
|
||
|
</div><div class="textblock"><div class="dynheader">
|
||
|
Include dependency graph for dynamic_stack.c:</div>
|
||
|
<div class="dyncontent">
|
||
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/dc1/dynamic__stack_8c__incl.svg" width="352" height="126"><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 id="nested-classes" 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="../../d4/d67/struct_d_array_stack.html">DArrayStack</a></td></tr>
|
||
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">to verify assumptions made by the program and print a diagnostic message if this assumption is false. <a href="../../d4/d67/struct_d_array_stack.html#details">More...</a><br /></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 id="typedef-members" name="typedef-members"></a>
|
||
|
Typedefs</h2></td></tr>
|
||
|
<tr class="memitem:aae116f0ceb8ee66fc9255762ccd7bfd6"><td class="memItemLeft" align="right" valign="top">typedef struct <a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#aae116f0ceb8ee66fc9255762ccd7bfd6">DArrayStack</a></td></tr>
|
||
|
<tr class="memdesc:aae116f0ceb8ee66fc9255762ccd7bfd6"><td class="mdescLeft"> </td><td class="mdescRight">to verify assumptions made by the program and print a diagnostic message if this assumption is false. <br /></td></tr>
|
||
|
<tr class="separator:aae116f0ceb8ee66fc9255762ccd7bfd6"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
</table><table class="memberdecls">
|
||
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
||
|
Functions</h2></td></tr>
|
||
|
<tr class="memitem:ab628a00140af56945b3f514cef0b3da0"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#ab628a00140af56945b3f514cef0b3da0">create_stack</a> (int cap)</td></tr>
|
||
|
<tr class="memdesc:ab628a00140af56945b3f514cef0b3da0"><td class="mdescLeft"> </td><td class="mdescRight">Create a <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> object. <br /></td></tr>
|
||
|
<tr class="separator:ab628a00140af56945b3f514cef0b3da0"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:ac01c5d1d1000ed68b5ff093c5ff36854"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#ac01c5d1d1000ed68b5ff093c5ff36854">double_array</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr, int cap)</td></tr>
|
||
|
<tr class="memdesc:ac01c5d1d1000ed68b5ff093c5ff36854"><td class="mdescLeft"> </td><td class="mdescRight">As this is stack implementation using dynamic array this function will expand the size of the stack by twice as soon as the stack is full. <br /></td></tr>
|
||
|
<tr class="separator:ac01c5d1d1000ed68b5ff093c5ff36854"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a072451a98105e776e63cb5dd792d562f"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#a072451a98105e776e63cb5dd792d562f">shrink_array</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr, int cap)</td></tr>
|
||
|
<tr class="memdesc:a072451a98105e776e63cb5dd792d562f"><td class="mdescLeft"> </td><td class="mdescRight">As this is stack implementation using dynamic array this function will shrink the size of stack by twice as soon as the stack's capacity and size has significant difference. <br /></td></tr>
|
||
|
<tr class="separator:a072451a98105e776e63cb5dd792d562f"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:aff3ec5aac14cef11d2666c0de4ba9b6e"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#aff3ec5aac14cef11d2666c0de4ba9b6e">push</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr, int <a class="el" href="../../df/dea/structdata.html">data</a>)</td></tr>
|
||
|
<tr class="memdesc:aff3ec5aac14cef11d2666c0de4ba9b6e"><td class="mdescLeft"> </td><td class="mdescRight">The push function pushes the element onto the stack. <br /></td></tr>
|
||
|
<tr class="separator:aff3ec5aac14cef11d2666c0de4ba9b6e"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a4540d7422773546a9b2f466bc49da068"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#a4540d7422773546a9b2f466bc49da068">pop</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr)</td></tr>
|
||
|
<tr class="memdesc:a4540d7422773546a9b2f466bc49da068"><td class="mdescLeft"> </td><td class="mdescRight">The pop function to pop an element from the stack. <br /></td></tr>
|
||
|
<tr class="separator:a4540d7422773546a9b2f466bc49da068"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a68471e91db2e62acd584744c24a09a4f"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#a68471e91db2e62acd584744c24a09a4f">peek</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr)</td></tr>
|
||
|
<tr class="memdesc:a68471e91db2e62acd584744c24a09a4f"><td class="mdescLeft"> </td><td class="mdescRight">To retrieve or fetch the first element of the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> or the element present at the top of the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a>. <br /></td></tr>
|
||
|
<tr class="separator:a68471e91db2e62acd584744c24a09a4f"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a9fe3f4e1147dd49a0ad4ca8f0228827d"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#a9fe3f4e1147dd49a0ad4ca8f0228827d">show_capacity</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr)</td></tr>
|
||
|
<tr class="memdesc:a9fe3f4e1147dd49a0ad4ca8f0228827d"><td class="mdescLeft"> </td><td class="mdescRight">To display the current capacity of the stack. <br /></td></tr>
|
||
|
<tr class="separator:a9fe3f4e1147dd49a0ad4ca8f0228827d"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a0eebbddad64a35d337093293466e26a1"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#a0eebbddad64a35d337093293466e26a1">isempty</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr)</td></tr>
|
||
|
<tr class="memdesc:a0eebbddad64a35d337093293466e26a1"><td class="mdescLeft"> </td><td class="mdescRight">The function is used to check whether the stack is empty or not and return true or false accordingly. <br /></td></tr>
|
||
|
<tr class="separator:a0eebbddad64a35d337093293466e26a1"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:ad46c93f9aac8431f73dc5e3a4413097e"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a> (<a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr)</td></tr>
|
||
|
<tr class="memdesc:ad46c93f9aac8431f73dc5e3a4413097e"><td class="mdescLeft"> </td><td class="mdescRight">Used to get the size of the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> or the number of elements present in the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a>. <br /></td></tr>
|
||
|
<tr class="separator:ad46c93f9aac8431f73dc5e3a4413097e"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d24/dynamic__stack_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
||
|
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <br /></td></tr>
|
||
|
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><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="../../d5/d24/dynamic__stack_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
||
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <br /></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>Dynamic <a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)" target="_blank">Stack</a>, just like Dynamic Array, is a stack data structure whose the length or capacity (maximum number of elements that can be stored) increases or decreases in real time based on the operations (like insertion or deletion) performed on it. </p>
|
||
|
<p>In this implementation, functions such as PUSH, POP, PEEK, show_capacity, isempty, and stack_size are coded to implement dynamic stack.</p>
|
||
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/SahilK-027" target="_blank">SahilK-027</a> </dd></dl>
|
||
|
</div><h2 class="groupheader">Typedef Documentation</h2>
|
||
|
<a id="aae116f0ceb8ee66fc9255762ccd7bfd6" name="aae116f0ceb8ee66fc9255762ccd7bfd6"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#aae116f0ceb8ee66fc9255762ccd7bfd6">◆ </a></span>DArrayStack</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">typedef struct <a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> <a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>to verify assumptions made by the program and print a diagnostic message if this assumption is false. </p>
|
||
|
<p>to provide a set of integer types with universally consistent definitions that are operating system-independent for IO operations for including functions involving memory allocation such as <code>malloc</code></p>
|
||
|
<p><a class="el" href="../../d4/d67/struct_d_array_stack.html" title="to verify assumptions made by the program and print a diagnostic message if this assumption is false.">DArrayStack</a> Structure of stack. </p>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<h2 class="groupheader">Function Documentation</h2>
|
||
|
<a id="ab628a00140af56945b3f514cef0b3da0" name="ab628a00140af56945b3f514cef0b3da0"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#ab628a00140af56945b3f514cef0b3da0">◆ </a></span>create_stack()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * create_stack </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>cap</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>Create a <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> object. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">cap</td><td>Capacity of stack </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>DArrayStack* Newly created stack object pointer </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 37</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 38</span> <a class="code hl_struct" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *ptr;</div>
|
||
|
<div class="line"><span class="lineno"> 39</span> ptr = (<a class="code hl_struct" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<a class="code hl_struct" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a>));</div>
|
||
|
<div class="line"><span class="lineno"> 40</span> ptr->capacity = cap;</div>
|
||
|
<div class="line"><span class="lineno"> 41</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> = -1;</div>
|
||
|
<div class="line"><span class="lineno"> 42</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a> = (<span class="keywordtype">int</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * cap);</div>
|
||
|
<div class="line"><span class="lineno"> 43</span> printf(<span class="stringliteral">"\nStack of capacity %d is successfully created.\n"</span>, ptr->capacity);</div>
|
||
|
<div class="line"><span class="lineno"> 44</span> <span class="keywordflow">return</span> (ptr);</div>
|
||
|
<div class="line"><span class="lineno"> 45</span>}</div>
|
||
|
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
|
||
|
<div class="ttc" id="astruct_d_array_stack_html"><div class="ttname"><a href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a></div><div class="ttdoc">to verify assumptions made by the program and print a diagnostic message if this assumption is false.</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:25</div></div>
|
||
|
<div class="ttc" id="astruct_d_array_stack_html_a0207dbf74f0f8623933bec50c36b4c4f"><div class="ttname"><a href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">DArrayStack::top</a></div><div class="ttdeci">int top</div><div class="ttdoc">to store capacity and top of the stack</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:26</div></div>
|
||
|
<div class="ttc" id="astruct_d_array_stack_html_aae446fbaecfeae53a970e7a63b74c126"><div class="ttname"><a href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">DArrayStack::arrPtr</a></div><div class="ttdeci">int * arrPtr</div><div class="ttdoc">array pointer</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:27</div></div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="ac01c5d1d1000ed68b5ff093c5ff36854" name="ac01c5d1d1000ed68b5ff093c5ff36854"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#ac01c5d1d1000ed68b5ff093c5ff36854">◆ </a></span>double_array()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * double_array </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>cap</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>As this is stack implementation using dynamic array this function will expand the size of the stack by twice as soon as the stack is full. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
<tr><td class="paramname">cap</td><td>Capacity of stack </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>DArrayStack*: Modified stack </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 56</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 57</span> <span class="keywordtype">int</span> newCap = 2 * cap;</div>
|
||
|
<div class="line"><span class="lineno"> 58</span> <span class="keywordtype">int</span> *temp;</div>
|
||
|
<div class="line"><span class="lineno"> 59</span> temp = (<span class="keywordtype">int</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * newCap);</div>
|
||
|
<div class="line"><span class="lineno"> 60</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>) + 1; i++)</div>
|
||
|
<div class="line"><span class="lineno"> 61</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 62</span> temp[i] = ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[i];</div>
|
||
|
<div class="line"><span class="lineno"> 63</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 64</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>);</div>
|
||
|
<div class="line"><span class="lineno"> 65</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a> = temp;</div>
|
||
|
<div class="line"><span class="lineno"> 66</span> ptr->capacity = newCap;</div>
|
||
|
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">return</span> ptr;</div>
|
||
|
<div class="line"><span class="lineno"> 68</span>}</div>
|
||
|
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a0eebbddad64a35d337093293466e26a1" name="a0eebbddad64a35d337093293466e26a1"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a0eebbddad64a35d337093293466e26a1">◆ </a></span>isempty()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int isempty </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>The function is used to check whether the stack is empty or not and return true or false accordingly. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>int returns 1 -> true OR returns 0 -> false </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 178</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 179</span> <span class="keywordflow">if</span> (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> == -1)</div>
|
||
|
<div class="line"><span class="lineno"> 180</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 181</span> <span class="keywordflow">return</span> 1;</div>
|
||
|
<div class="line"><span class="lineno"> 182</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 183</span> <span class="keywordflow">return</span> 0;</div>
|
||
|
<div class="line"><span class="lineno"> 184</span>}</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="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="paramtype">void </td>
|
||
|
<td class="paramname"></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>Main function. </p>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 247</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 248</span> <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
||
|
<div class="line"><span class="lineno"> 249</span> <span class="keywordflow">return</span> 0;</div>
|
||
|
<div class="line"><span class="lineno"> 250</span>}</div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:199</div></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="../../d5/d24/dynamic__stack_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="308" height="307"><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="a68471e91db2e62acd584744c24a09a4f" name="a68471e91db2e62acd584744c24a09a4f"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a68471e91db2e62acd584744c24a09a4f">◆ </a></span>peek()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int peek </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>To retrieve or fetch the first element of the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> or the element present at the top of the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a>. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>int Top of the stack </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 153</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 154</span> <span class="keywordflow">if</span> (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> == -1)</div>
|
||
|
<div class="line"><span class="lineno"> 155</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 156</span> printf(<span class="stringliteral">"Stack is empty UNDERFLOW \n"</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 157</span> <span class="keywordflow">return</span> -1;</div>
|
||
|
<div class="line"><span class="lineno"> 158</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 159</span> <span class="keywordflow">return</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>];</div>
|
||
|
<div class="line"><span class="lineno"> 160</span>}</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a4540d7422773546a9b2f466bc49da068" name="a4540d7422773546a9b2f466bc49da068"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a4540d7422773546a9b2f466bc49da068">◆ </a></span>pop()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int pop </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>The pop function to pop an element from the stack. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>int Popped value </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 125</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 126</span> <span class="keywordflow">if</span> (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> == -1)</div>
|
||
|
<div class="line"><span class="lineno"> 127</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 128</span> printf(<span class="stringliteral">"Stack is empty UNDERFLOW \n"</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 129</span> <span class="keywordflow">return</span> -1;</div>
|
||
|
<div class="line"><span class="lineno"> 130</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 131</span> <span class="keywordtype">int</span> ele = ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>];</div>
|
||
|
<div class="line"><span class="lineno"> 132</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>] = 0;</div>
|
||
|
<div class="line"><span class="lineno"> 133</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> = (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> - 1);</div>
|
||
|
<div class="line"><span class="lineno"> 134</span> <span class="keywordflow">if</span> ((ptr->capacity) % 2 == 0)</div>
|
||
|
<div class="line"><span class="lineno"> 135</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 136</span> <span class="keywordflow">if</span> (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> <= (ptr->capacity / 2) - 1)</div>
|
||
|
<div class="line"><span class="lineno"> 137</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 138</span> ptr = <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#a072451a98105e776e63cb5dd792d562f">shrink_array</a>(ptr, ptr->capacity);</div>
|
||
|
<div class="line"><span class="lineno"> 139</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 140</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 141</span> printf(<span class="stringliteral">"Successfully popped: %d\n"</span>, ele);</div>
|
||
|
<div class="line"><span class="lineno"> 142</span> <span class="keywordflow">return</span> ele;</div>
|
||
|
<div class="line"><span class="lineno"> 143</span>}</div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_a072451a98105e776e63cb5dd792d562f"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#a072451a98105e776e63cb5dd792d562f">shrink_array</a></div><div class="ttdeci">DArrayStack * shrink_array(DArrayStack *ptr, int cap)</div><div class="ttdoc">As this is stack implementation using dynamic array this function will shrink the size of stack by tw...</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:79</div></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="../../d5/d24/dynamic__stack_8c_a4540d7422773546a9b2f466bc49da068_cgraph.svg" width="194" height="36"><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="aff3ec5aac14cef11d2666c0de4ba9b6e" name="aff3ec5aac14cef11d2666c0de4ba9b6e"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#aff3ec5aac14cef11d2666c0de4ba9b6e">◆ </a></span>push()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int push </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</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>The push function pushes the element onto the stack. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
<tr><td class="paramname">data</td><td>Value to be pushed onto stack </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>int Position of top pointer </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 102</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 103</span> <span class="keywordflow">if</span> (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> == (ptr->capacity) - 1)</div>
|
||
|
<div class="line"><span class="lineno"> 104</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 105</span> ptr = <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ac01c5d1d1000ed68b5ff093c5ff36854">double_array</a>(ptr, ptr->capacity);</div>
|
||
|
<div class="line"><span class="lineno"> 106</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>++;</div>
|
||
|
<div class="line"><span class="lineno"> 107</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>] = <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>;</div>
|
||
|
<div class="line"><span class="lineno"> 108</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 109</span> <span class="keywordflow">else</span></div>
|
||
|
<div class="line"><span class="lineno"> 110</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 111</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>++;</div>
|
||
|
<div class="line"><span class="lineno"> 112</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>] = <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>;</div>
|
||
|
<div class="line"><span class="lineno"> 113</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 114</span> printf(<span class="stringliteral">"Successfully pushed : %d\n"</span>, <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>);</div>
|
||
|
<div class="line"><span class="lineno"> 115</span> <span class="keywordflow">return</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>;</div>
|
||
|
<div class="line"><span class="lineno"> 116</span>}</div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_ac01c5d1d1000ed68b5ff093c5ff36854"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#ac01c5d1d1000ed68b5ff093c5ff36854">double_array</a></div><div class="ttdeci">DArrayStack * double_array(DArrayStack *ptr, int cap)</div><div class="ttdoc">As this is stack implementation using dynamic array this function will expand the size of the stack b...</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:55</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><!-- 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="../../d5/d24/dynamic__stack_8c_aff3ec5aac14cef11d2666c0de4ba9b6e_cgraph.svg" width="204" height="110"><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="a9fe3f4e1147dd49a0ad4ca8f0228827d" name="a9fe3f4e1147dd49a0ad4ca8f0228827d"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a9fe3f4e1147dd49a0ad4ca8f0228827d">◆ </a></span>show_capacity()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int show_capacity </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>To display the current capacity of the stack. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>int Current capacity of the stack </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 168</span>{ <span class="keywordflow">return</span> ptr->capacity; }</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a072451a98105e776e63cb5dd792d562f" name="a072451a98105e776e63cb5dd792d562f"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a072451a98105e776e63cb5dd792d562f">◆ </a></span>shrink_array()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * shrink_array </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>cap</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>As this is stack implementation using dynamic array this function will shrink the size of stack by twice as soon as the stack's capacity and size has significant difference. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
<tr><td class="paramname">cap</td><td>Capacity of stack </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>DArrayStack*: Modified stack </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 80</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 81</span> <span class="keywordtype">int</span> newCap = cap / 2;</div>
|
||
|
<div class="line"><span class="lineno"> 82</span> <span class="keywordtype">int</span> *temp;</div>
|
||
|
<div class="line"><span class="lineno"> 83</span> temp = (<span class="keywordtype">int</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * newCap);</div>
|
||
|
<div class="line"><span class="lineno"> 84</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < (ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a>) + 1; i++)</div>
|
||
|
<div class="line"><span class="lineno"> 85</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 86</span> temp[i] = ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>[i];</div>
|
||
|
<div class="line"><span class="lineno"> 87</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 88</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a>);</div>
|
||
|
<div class="line"><span class="lineno"> 89</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#aae446fbaecfeae53a970e7a63b74c126">arrPtr</a> = temp;</div>
|
||
|
<div class="line"><span class="lineno"> 90</span> ptr->capacity = newCap;</div>
|
||
|
<div class="line"><span class="lineno"> 91</span> <span class="keywordflow">return</span> ptr;</div>
|
||
|
<div class="line"><span class="lineno"> 92</span>}</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="ad46c93f9aac8431f73dc5e3a4413097e" name="ad46c93f9aac8431f73dc5e3a4413097e"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#ad46c93f9aac8431f73dc5e3a4413097e">◆ </a></span>stack_size()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int stack_size </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> * </td>
|
||
|
<td class="paramname"><em>ptr</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>Used to get the size of the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> or the number of elements present in the <a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a>. </p>
|
||
|
<dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptr</td><td><a class="el" href="../../dd/d10/struct_stack.html" title="for printf() and scanf()">Stack</a> pointer </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>int size of stack </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 193</span>{ <span class="keywordflow">return</span> ptr-><a class="code hl_variable" href="../../d4/d67/struct_d_array_stack.html#a0207dbf74f0f8623933bec50c36b4c4f">top</a> + 1; }</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">◆ </a></span>test()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="mlabels">
|
||
|
<tr>
|
||
|
<td class="mlabels-left">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">static void test </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">void </td>
|
||
|
<td class="paramname"></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</td>
|
||
|
<td class="mlabels-right">
|
||
|
<span class="mlabels"><span class="mlabel">static</span></span> </td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>Self-test implementations. </p>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
||
|
<div class="fragment"><div class="line"><span class="lineno"> 200</span>{</div>
|
||
|
<div class="line"><span class="lineno"> 201</span> <a class="code hl_struct" href="../../d4/d67/struct_d_array_stack.html">DArrayStack</a> *NewStack;</div>
|
||
|
<div class="line"><span class="lineno"> 202</span> <span class="keywordtype">int</span> capacity = 1;</div>
|
||
|
<div class="line"><span class="lineno"> 203</span> NewStack = <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ab628a00140af56945b3f514cef0b3da0">create_stack</a>(capacity);</div>
|
||
|
<div class="line"><span class="lineno"> 204</span> uint64_t arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};</div>
|
||
|
<div class="line"><span class="lineno"> 205</span> </div>
|
||
|
<div class="line"><span class="lineno"> 206</span> printf(<span class="stringliteral">"\nTesting Empty stack: "</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 207</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack) == 0);</div>
|
||
|
<div class="line"><span class="lineno"> 208</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#a0eebbddad64a35d337093293466e26a1">isempty</a>(NewStack) == 1);</div>
|
||
|
<div class="line"><span class="lineno"> 209</span> printf(<span class="stringliteral">"Size of an empty stack is %d\n"</span>, <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack));</div>
|
||
|
<div class="line"><span class="lineno"> 210</span> </div>
|
||
|
<div class="line"><span class="lineno"> 211</span> printf(<span class="stringliteral">"\nTesting PUSH operation:\n"</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 212</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 12; ++i)</div>
|
||
|
<div class="line"><span class="lineno"> 213</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 214</span> <span class="keywordtype">int</span> topVal = <a class="code hl_function" href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">push</a>(NewStack, arr[i]);</div>
|
||
|
<div class="line"><span class="lineno"> 215</span> printf(<span class="stringliteral">"Size: %d, Capacity: %d\n\n"</span>, <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack),</div>
|
||
|
<div class="line"><span class="lineno"> 216</span> <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#a9fe3f4e1147dd49a0ad4ca8f0228827d">show_capacity</a>(NewStack));</div>
|
||
|
<div class="line"><span class="lineno"> 217</span> assert(topVal == i);</div>
|
||
|
<div class="line"><span class="lineno"> 218</span> assert(peek(NewStack) == arr[i]);</div>
|
||
|
<div class="line"><span class="lineno"> 219</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack) == i + 1);</div>
|
||
|
<div class="line"><span class="lineno"> 220</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#a0eebbddad64a35d337093293466e26a1">isempty</a>(NewStack) == 0);</div>
|
||
|
<div class="line"><span class="lineno"> 221</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 222</span> </div>
|
||
|
<div class="line"><span class="lineno"> 223</span> printf(<span class="stringliteral">"\nTesting POP operation:\n"</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 224</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 11; i > -1; --i)</div>
|
||
|
<div class="line"><span class="lineno"> 225</span> {</div>
|
||
|
<div class="line"><span class="lineno"> 226</span> peek(NewStack);</div>
|
||
|
<div class="line"><span class="lineno"> 227</span> assert(peek(NewStack) == arr[i]);</div>
|
||
|
<div class="line"><span class="lineno"> 228</span> <span class="keywordtype">int</span> ele = <a class="code hl_function" href="../../da/d96/infix__to__postfix2_8c.html#a312e7f6c761a199c1369fbe651e084f0">pop</a>(NewStack);</div>
|
||
|
<div class="line"><span class="lineno"> 229</span> assert(ele == arr[i]);</div>
|
||
|
<div class="line"><span class="lineno"> 230</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack) == i);</div>
|
||
|
<div class="line"><span class="lineno"> 231</span> }</div>
|
||
|
<div class="line"><span class="lineno"> 232</span> </div>
|
||
|
<div class="line"><span class="lineno"> 233</span> printf(<span class="stringliteral">"\nTesting Empty stack size: "</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 234</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack) == 0);</div>
|
||
|
<div class="line"><span class="lineno"> 235</span> assert(<a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#a0eebbddad64a35d337093293466e26a1">isempty</a>(NewStack) == 1);</div>
|
||
|
<div class="line"><span class="lineno"> 236</span> printf(<span class="stringliteral">"Size of an empty stack is %d\n"</span>, <a class="code hl_function" href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a>(NewStack));</div>
|
||
|
<div class="line"><span class="lineno"> 237</span> </div>
|
||
|
<div class="line"><span class="lineno"> 238</span> printf(<span class="stringliteral">"\nTesting POP operation on empty stack: "</span>);</div>
|
||
|
<div class="line"><span class="lineno"> 239</span> assert(<a class="code hl_function" href="../../da/d96/infix__to__postfix2_8c.html#a312e7f6c761a199c1369fbe651e084f0">pop</a>(NewStack) == -1);</div>
|
||
|
<div class="line"><span class="lineno"> 240</span>}</div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_a0eebbddad64a35d337093293466e26a1"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#a0eebbddad64a35d337093293466e26a1">isempty</a></div><div class="ttdeci">int isempty(DArrayStack *ptr)</div><div class="ttdoc">The function is used to check whether the stack is empty or not and return true or false accordingly.</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:177</div></div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_a9fe3f4e1147dd49a0ad4ca8f0228827d"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#a9fe3f4e1147dd49a0ad4ca8f0228827d">show_capacity</a></div><div class="ttdeci">int show_capacity(DArrayStack *ptr)</div><div class="ttdoc">To display the current capacity of the stack.</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:168</div></div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_ab628a00140af56945b3f514cef0b3da0"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#ab628a00140af56945b3f514cef0b3da0">create_stack</a></div><div class="ttdeci">DArrayStack * create_stack(int cap)</div><div class="ttdoc">Create a Stack object.</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:36</div></div>
|
||
|
<div class="ttc" id="adynamic__stack_8c_html_ad46c93f9aac8431f73dc5e3a4413097e"><div class="ttname"><a href="../../d5/d24/dynamic__stack_8c.html#ad46c93f9aac8431f73dc5e3a4413097e">stack_size</a></div><div class="ttdeci">int stack_size(DArrayStack *ptr)</div><div class="ttdoc">Used to get the size of the Stack or the number of elements present in the Stack.</div><div class="ttdef"><b>Definition:</b> dynamic_stack.c:193</div></div>
|
||
|
<div class="ttc" id="ainfix__to__postfix2_8c_html_a312e7f6c761a199c1369fbe651e084f0"><div class="ttname"><a href="../../da/d96/infix__to__postfix2_8c.html#a312e7f6c761a199c1369fbe651e084f0">pop</a></div><div class="ttdeci">char pop()</div><div class="ttdoc">Function to pop from the stack.</div><div class="ttdef"><b>Definition:</b> infix_to_postfix2.c:45</div></div>
|
||
|
<div class="ttc" id="ainfix__to__postfix_8c_html_a613462735d30cae1b85b606ecab30554"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">push</a></div><div class="ttdeci">void push(struct Stack *p, char ch)</div><div class="ttdoc">push function</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:55</div></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="../../d5/d24/dynamic__stack_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="211" height="307"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div><!-- contents -->
|
||
|
</div><!-- doc-content -->
|
||
|
<!-- 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_2176ba3565d8b1fe2a106d18679cc7bf.html">stack</a></li><li class="navelem"><a class="el" href="../../d5/d24/dynamic__stack_8c.html">dynamic_stack.c</a></li>
|
||
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|