This repository contains a simple implementation of a Stack data structure in JavaScript. The Stack class allows you to perform common stack operations like push, pop, peek, and check the stack size.
- push(n): Add an element
nto the top of the stack. - pop(): Remove and return the top element from the stack. If the stack is empty, it alerts the user.
- peek(): View the top element without removing it.
- size(): Get the number of elements currently in the stack.
- is_empty(): Check if the stack is empty.
| Method | Description |
|---|---|
push(n) | Adds element n to the top of the stack. |
pop() | Removes and returns the top element. |
peek() | Returns the top element without removing. |
size() | Returns the number of elements in stack. |
is_empty() | Checks if the stack is empty. |