You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, I start with implementing the class Stack which is used for the stack.
In order to store the data in the stack, I am using the constructor method to create and initialize the stack. The data variable will hold elements to our stack.
The push method is used to add elements to our stack.
The pop method is used to remove the last element from our stack.
The peek method is used to return the last element in the data property (our array).
The empty method is used to check if there are any values in the stack.