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 00a204d commit 28e7287Copy full SHA for 28e7287
Stack.js
@@ -0,0 +1,29 @@
1
+// Stack using a Singly Linked List
2
+
3
+class Node {
4
+ constructor(value) {
5
+ this.value = value;
6
+ this.next = null;
7
+ }
8
+}
9
10
+class Stack {
11
12
+ this.first = null;
13
+ this.last = null;
14
+ this.size = 0;
15
16
17
+ push(value) {
18
+ const node = new Node(value);
19
+ if (!this.size) this.first = this.last = node;
20
+ else {
21
+ node.next = this.first;
22
+ this.first = node;
23
24
25
+ this.size++;
26
27
+ return this.size;
28
29
0 commit comments