-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.js
More file actions
37 lines (37 loc) · 750 Bytes
/
stack.js
File metadata and controls
37 lines (37 loc) · 750 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
class stack{
data;
next;
constructor(data){
this.data=data;
this.next=null;
}
push(data){
let temp=new stack(data);
temp.next=this.next;
this.next=temp;
}
pop(){
this.next=this.next.next;
}
top(){
return this.next.data;
}
print(){
let temp=this;
while(temp!=null){
console.log(temp.data);
temp=temp.next;
}
}
}
module.exports={
structure:stack,
description:"Stack",
methods:{
push:"Pushes an element into the stack",
pop:"Pops an element from the stack",
top:"Returns the top element of the stack",
print:"Prints the stack"
},
category:"Stack"
};