As mentioned earlier, a stack allows you to do an operation only with the last index. So, the operations possible on a stack are as follows:
- Insertion: This allows you to insert an element at last index (Top) of the stack. This operation is also called a Push operation.
- Deletion: This allows you to delete the element at last index (Top) of the stack. This operation is also called a Pop operation.
In addition to these primary operations, the stack can also allow a few secondary operations, such as the following:
- Fetch: Fetches the top of the stack, also called Peek
- Size: Returns the size of the stack
- isEmpty: Tells whether the stack is empty or not
- isFull: Tells whether the stack is full or not
If we closely observe the operations it allows us to do, we'll notice that the element that is being inserted (Push) last is deleted and (Pop) first. On the...