{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/stack","result":{"data":{"markdownRemark":{"html":"<h2>What is stack?</h2>\n<p>Stack seems like the most basic of data structures.\nExamples of stack is:</p>\n<ul>\n<li>Undo/Redo in text editors</li>\n<li>Going back and forth on browsers</li>\n<li>Recursion Recursion Recursion</li>\n</ul>\n<h3>How can I describe stack operations?</h3>\n<p>LIFO stands for Last-in-first-out</p>\n<table>\n<thead>\n<tr>\n<th>Method</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>push</td>\n<td>pushing an element on to the stack</td>\n</tr>\n<tr>\n<td>pop</td>\n<td>removing the 'top' element from the stack</td>\n</tr>\n<tr>\n<td>peek</td>\n<td>look at the top element without taking it out</td>\n</tr>\n<tr>\n<td>empty</td>\n<td>returns true if stack is empty</td>\n</tr>\n<tr>\n<td>swap</td>\n<td>swap the two top elements</td>\n</tr>\n</tbody>\n</table>\n<p>This helps a developer to understand how to add, remove and organize data in a sequential way.</p>\n<h2>Javascript Call Stack</h2>\n<ul>\n<li>A call stack is a data structure that uses the LIFO principle to temporarily store and manage function invocation.</li>\n<li>Code execution is synchronous</li>\n<li>It is single threaded</li>\n</ul>\n<h2>What is a stack overflow?</h2>\n<p>A stack overflow is when the browser has a maximum stack call that it can call before throwing an error. This happens when there is a recursive function that call itself.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-javascript line-numbers\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">neverGonnaGiveYouUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">neverGonnaGiveYouUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">neverGonnaGiveYouUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span></span></pre></div>","excerpt":"What is stack? Stack seems like the most basic of data structures.\nExamples of stack is: Undo/Redo in text editors Going back and forth on browsers Recursion…","frontmatter":{"date":"27 February, 2020","path":"/blog/stack","title":"Data structures : Stack "},"fields":{"readingTime":{"text":"2 min read"}}}},"pageContext":{}}}