We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dd7c6b4 commit 3149f8fCopy full SHA for 3149f8f
stack-object.js
@@ -0,0 +1,34 @@
1
+class Stack {
2
+ constructor() {
3
+ this.items = {};
4
+ this.head = 0;
5
+ }
6
+
7
+ push(element) {
8
+ this.items[this.head] = element;
9
+ this.head++;
10
11
12
+ pop() {
13
+ const item = this.items[this.head - 1];
14
+ delete this.items[this.head - 1];
15
+ this.head--;
16
+ return item;
17
18
19
+ peek() {
20
+ return this.items[this.head - 1];
21
22
23
+ size() {
24
+ return this.head;
25
26
27
+ isEmpty() {
28
+ return this.head === 0;
29
30
31
+ print() {
32
+ console.log(this.items);
33
34
+}
0 commit comments