Question:

Explain stack.

Show Hint

Think of a stack of plates. You add a new plate to the top (push), and when you need a plate, you take one from the top (pop).
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

A stack is a linear data structure that follows the Last-In, First-Out (LIFO) principle. This means that the last element added to the stack will be the first element to be removed. The two primary operations on a stack are:

Push: Adds an element to the top of the stack.
Pop: Removes the element from the top of the stack.
Other operations include `Peek` or `Top` (view the top element without removing it) and `isEmpty` (check if the stack is empty).
Was this answer helpful?
0
0