We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 823e1f7 commit dd7c6b4Copy full SHA for dd7c6b4
stack-array.js
@@ -0,0 +1,40 @@
1
+class Stack {
2
+ constructor() {
3
+ this.items = [];
4
+ }
5
+
6
+ push(element) {
7
+ this.items.push(element);
8
9
10
+ pop() {
11
+ return this.items.pop();
12
13
14
+ peek() {
15
+ return this.items[this.items.length - 1];
16
17
18
+ isEmpty() {
19
+ return this.items.length === 0;
20
21
22
+ size() {
23
+ return this.items.length;
24
25
26
+ print() {
27
+ console.log(this.items.toString());
28
29
+}
30
31
+const stack = new Stack();
32
+console.log(stack.isEmpty());
33
+stack.push(20);
34
+stack.push(10);
35
+stack.push(30);
36
+console.log(stack.size());
37
+stack.print();
38
+console.log(stack.pop());
39
+console.log(stack.peek());
40
0 commit comments