-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.js
More file actions
47 lines (34 loc) · 971 Bytes
/
queue.js
File metadata and controls
47 lines (34 loc) · 971 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
var Stack =function(){
this.arr=[];
this.top=-1;
this.push=function(value){
if(this.top===-1){
this.top++;
}
this.arr[this.top]=value;
this.top++;
}
this.pop=function(){
// this.store= "";
if(this.top===-1){
return undefined;
}
this.top -= 1;
this.store=this.arr[this.top];
delete this.arr[this.top];
console.log(this.store)
return this.store;
}
}
var stack1= new Stack()
stack1.push(7);
stack1.push(6);
stack1.push(5);
stack1.push(12);
console.log(stack1);
console.log("Pop", stack1.pop());
console.log("Pop", stack1.pop());
console.log("Pop", stack1.pop());
console.log("Pop", stack1.pop());
console.log("Pop", stack1.pop());
console.log("Pop", stack1.pop());