-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.js
More file actions
51 lines (43 loc) · 876 Bytes
/
Copy pathstack.js
File metadata and controls
51 lines (43 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { SinglyLinkedList as List } from "./singlyLinkedList.js";
class Stack {
constructor() {
this.list = new List();
}
// push
push(data) {
this.list.prepend(data);
}
// pop
pop() {
return this.list.removeHead();
}
// peek
peek() {
return this.list.head.data;
}
// isEmpty
isEmpty() {
return this.list.isEmpty();
}
// size
size() {
return this.list.getSize();
}
// print
print() {
return this.list.print();
}
}
const stack = new Stack();
stack.push(10);
stack.push(20);
stack.push(30);
stack.print();
console.log("----------------------------");
console.log("peek: ", stack.peek());
console.log("pop: ", stack.pop());
stack.print();
console.log("----------------------------");
console.log("peek: ", stack.peek());
console.log("isEmpty: ", stack.isEmpty());
console.log("size: ", stack.size());