if your are using an array as stack (LIFO) you can use push and pop to add an remove item in stack
But you can't get the top of the stack. you need to pop and push or calculate the legnth of the stack to get the last item.
this sample code add top method tio get last item.