Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
71 lines (53 loc) · 1.19 KB

File metadata and controls

71 lines (53 loc) · 1.19 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @author SkylineBin
* @time 2018-8-20
* @function Using Stack
*/
function Stack () {
var items = [];
// push a element data into this stack
this.push = function (element) {
items.push(element);
}
// pop a data from this stack then return this data
this.pop = function () {
return items.pop();
}
// return the stack top data
this.peek = function () {
return items[items.length - 1];
}
// check this stack is empty
this.isEmpty = function () {
return items.length == 0;
}
// get the length of this stack
this.size = function () {
return items.length;
}
// clear this stack
this.clear = function () {
items = [];
}
// print this stack
this.print = function () {
console.log(items.toString());
}
}
// console.log(Stack);
// init one Stack Class
let stack = new Stack();
console.log(stack.isEmpty());
// push data into this stack
stack.push(5);
stack.push(8);
console.log(stack.peek());
stack.push(7);
console.log(stack.size());
console.log(stack.isEmpty());
stack.push(9);
stack.print();
stack.pop();
stack.pop();
console.log(stack.size());
stack.print();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.