forked from super30admin/PreCourse-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise_2.js
36 lines (36 loc) · 864 Bytes
/
Exercise_2.js
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
class StackAsLinkedList {
static stackNode = class {
constructor(d) {
//Constructor here
this.data = d;
this.next = null;
}
}
function isEmpty() {
//Write your code here for the condition if stack is empty.
}
function push(data) {
//Write code to push data to the stack.
}
function pop() {
//If Stack Empty Return 0 and print "Stack Underflow"
//Write code to pop the topmost element of stack.
//Also return the popped element
}
function peek() {
//Write code to just return the topmost element without removing it.
}
}
//Driver code
const sll = new StackAsLinkedList();
sll.push(10);
sll.push(20);
sll.push(30);
console.log(sll.pop() + " popped from stack");
console.log("Top element is " + sll.peek());