Last active
June 20, 2023 09:52
-
-
Save alexsoyes/454ddba2e035600e6c75448e048528f2 to your computer and use it in GitHub Desktop.
Exemple TypeScript : Piles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack<T> { | |
stack: T[]; | |
constructor() { | |
this.stack = []; | |
} | |
push(value: T) { | |
this.stack.push(value); | |
} | |
pop(): T | undefined { | |
return this.stack.pop(); | |
} | |
isEmpty(): boolean { | |
return this.stack.length === 0; | |
} | |
} | |
const stack = new Stack<number>(); | |
stack.push(1); | |
stack.push(2); | |
stack.push(3); | |
console.log(stack.pop()); // Output: 3 | |
console.log(stack['stack']); // Output: [1, 2] | |
console.log(stack.isEmpty()); // Output: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment