Step 1: Check Overflow
Always verify if `IsFull()` is true. If the internal array has reached its maximum size, pushing will cause a memory violation (Overflow).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Pushing is the act of adding a new element to the top of the Stack. It runs in O(1) constant time.
Always verify if `IsFull()` is true. If the internal array has reached its maximum size, pushing will cause a memory violation (Overflow).
Increment the `top` pointer by 1. Initially, `top` is -1, so the first push moves `top` to index 0.
Write the new value to the array exactly at the new `top` index. The element is now officially part of the stack.