-
Notifications
You must be signed in to change notification settings - Fork 2
/
stack. and queue.js
40 lines (32 loc) · 1.07 KB
/
stack. and queue.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
37
38
39
40
var values =[];
values.push("car");
values.push("bike");
values.push("truck");
values.push("tanker");
values.push("airplane");
console.log(values); // print all values in stack
console.log(values.length); // length 5
var v1=values.pop(); // airplane removed
var v2=values.pop(); // tanker removed
console.log(v1); //printing poped value
console.log(v2); //printing poped value
console.log(values); // print all values in stack
console.log(values.length); // length 3
// queue
var values1 =[];
values1.push("sam");
values1.push("mike");
values1.push("zack");
values1.push("finn");
values1.push("frade");
console.log(values1); // print all values in stack
console.log(values1.length); // length 5
var v3=values1.shift(); // sam removed
var v4=values1.shift(); // mike removed
console.log(v3); //printing poped value
console.log(v4); //printing poped value
console.log(values1); // print all values in stack
console.log(values1.length); // length 3
values1.unshift("jenny"); // added at the top of the stack
console.log(values1);
console.log(values1[0]); //showed here