Stack•Easy
Peek / Top
Stack Peek / Top Operation

The Peek (or Top) operation returns the value of the top element of the stack without removing it. It is a read-only operation.
Key Rules
- Empty Check: Before reading, verify if the stack has elements (
top >= 0). If the stack is empty, it returns an error value or exception. - Access Top: Directly return
arr[top]. Unlikepop, thetopindex pointer is not decremented.
Visually
Peek() returns 30:
Index [2]: [ 30 ] ◄top (Highlighted / Read)
Index [1]: [ 20 ]
Index [0]: [ 10 ]