In the previous article, we saw how data is inserted and deleted in an array. In that case we could insert data at any place throughout the array. However, there are situations when we only need to add and retrieve data form the ends of the array. Stacks are one of the examples of this. Stacks are data structures in which data could be added and retrieved only from one end (also known as the TOP of the stack). Suppose we insert 5, 6, 9 to the stack consecutively then while retrieving the first one to be retrieved will be 9 then 6 and then 5. That is why stacks are also known as Last-In-First-Out (or LIFO) structure. A few terms regarding stacks: Stack: Stack is a user-defined data structure. It is most commonly represented by linked-lists and arrays. In this article, we will be representing stacks with arrays. Push: Adding data to the stack is known as pushing. Pop: Retrieving data from the stack is known as popping. Let us have look at this process with the help of an...
A resource for learning PHP, HTML, CSS, JavaScript, C++, etc.