- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.js
More file actions
Latest commit
43 lines (37 loc) · 811 Bytes
/
Copy pathStack.js
File metadata and controls
43 lines (37 loc) · 811 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
classNode{
constructor(value){
this.value=value;
this.next=null;
}
}
classStack{
constructor(){
this.first=null;
this.last=null;
this.size=0;
}
push(val){
letnewNode=newNode(val);
if(!this.first){
this.first=newNode;
this.last=newNode;
}else{
lettemp=this.first;
this.first=newNode;
this.first.next=temp;
}
return++this.size;
}
pop(){
if(!this.first){
returnnull;
}
lettemp=this.first;
if(this.first===this.last){
this.last=null;
}
this.first=this.first.next;
this.size--;
returntemp.value;
}
}