Aller au contenu

🧱 Stack – Data Structure

A stack is a linear data structure that follows the LIFO principle (Last In, First Out), meaning the last element inserted is the first to be removed.


⚙️ Basic Stack Operations

Here are the fundamental operations that can be performed on a stack:

  • 🔼 push() – Inserts an element into the stack
  • 🔽 pop() – Removes the last inserted element
  • 🔍 top() – Returns the top element of the stack without removing it
  • isEmpty() – Returns true if the stack is empty, otherwise false
  • 📏 size() – Returns the current size of the stack

🧪 Implemented Methods

In this package, we implemented the following methods to manipulate a stack:

🗃️ Data Structure 🛠️ Available Methods
Stack push(), pop(), peek(), is_empty(), size(), display()

🔁 Note: The peek() method is equivalent to top(), allowing you to view the top element without removing it.