File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Initialize your data structure here.
3
+ */
4
+ const MyStack = function ( ) {
5
+ this . stack = [ ]
6
+ } ;
7
+
8
+ /**
9
+ * Push element x onto stack.
10
+ * @param {number } x
11
+ * @return {void }
12
+ */
13
+ MyStack . prototype . push = function ( x ) {
14
+ this . stack . push ( x )
15
+ } ;
16
+
17
+ /**
18
+ * Removes the element on top of the stack and returns that element.
19
+ * @return {number }
20
+ */
21
+ MyStack . prototype . pop = function ( ) {
22
+ return this . stack . pop ( )
23
+ } ;
24
+
25
+ /**
26
+ * Get the top element.
27
+ * @return {number }
28
+ */
29
+ MyStack . prototype . top = function ( ) {
30
+ return this . stack . length === 0 ? null : this . stack [ this . stack . length - 1 ]
31
+ } ;
32
+
33
+ /**
34
+ * Returns whether the stack is empty.
35
+ * @return {boolean }
36
+ */
37
+ MyStack . prototype . empty = function ( ) {
38
+ return this . stack . length === 0
39
+ } ;
40
+
41
+ /**
42
+ * Your MyStack object will be instantiated and called as such:
43
+ * var obj = Object.create(MyStack).createNew()
44
+ * obj.push(x)
45
+ * var param_2 = obj.pop()
46
+ * var param_3 = obj.top()
47
+ * var param_4 = obj.empty()
48
+ */
You can’t perform that action at this time.
0 commit comments