Implementing a stack
MATL, 6 bytes
&quot;@?@}x

Input is a row vector of numbers.
The final stack is shown upside down, with the most recent element below.
Try it online! Or verify all test cases.
Explanation
&quot;         % For each element in the input (implicit)
  @       %   Push current element
  ?       %   If non-zero (this consumes the current element)
    @     %     Push current element again
  }       %   Else
    x     %     Delete most recent element
          %   End (implicit)
          % End (implicit)
          % Display (implicit)