.top()
The .top()
method returns the top element on the stack
. This will be the most recently added element on the stack
since they follow a last-in first-out (LIFO) insertion order.
Syntax
The .top()
method can be called on a stack
using the following syntax:
stackName.top();
Codebyte Example
The following example calls the .top()
method to print successive entries from myStack
: