-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.ts
More file actions
34 lines (27 loc) · 674 Bytes
/
Copy pathstack.ts
File metadata and controls
34 lines (27 loc) · 674 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
export class Stack {
num: number[] = [];
constructor() {
}
add(num1: number) {
return this.num.push(num1);
}
remove(): number {
return this.num.pop();
}
nElement(): number {
return this.num.length;
}
clear() {
this.num.splice(0, this.num.length);
}
top(): number {
let lastNumber: number = 0;
for (let i = 0; i < this.num.length; i++) {
lastNumber = this.num[i];
}
return lastNumber;
}
toString(): string {
return `Elements of List: ${this.num} | Element on Top: ${this.top()} | Number of Elements: ${this.nElement()} `
}
}