-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathStack.js
More file actions
58 lines (57 loc) · 1.21 KB
/
Stack.js
File metadata and controls
58 lines (57 loc) · 1.21 KB
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
class Stack {
constructor() {
this.top = 0;
this.dataStore = [];
}
/**
* @name push
* @param {String} elem
* @description
* handler function which will add new element in stack and increament top value by 1
*/
push(element) {
this.dataStore[this.top++] = element;
}
/**
* @name pop
* @param {String} elem
* @description
* handler function which will remove element in stack and decreament top value by 1
* @returns {String} RemoveElement
*/
pop() {
this.top--;
return this.dataStore.pop()
}
/**
* @name peek
* @param {String} elem
* @description
* handler function which provide the top element on stack
* @returns {String} TopElement
*/
peek() {
return this.dataStore[this.top - 1];
}
/**
* @name length
* @param {String} elem
* @description
* handler function which provide the length on element
* @returns {Number}
*/
length() {
return this.top;
}
/**
* @name clear
* @description
* handler function which will clear stack
* @returns {Void}
*/
clear() {
this.top = 0;
this.dataStore = []
}
}
module.exports = Stack