반응형 stack1 스택(Stack) - 자바스크립트, JS class Stack { constructor() { this.items = []; } // 스택에 요소 추가 push(element) { this.items.push(element); } // 스택에서 가장 위의 요소 제거 후 반환 pop() { if (this.isEmpty()) { return "Stack is empty."; } return this.items.pop(); } // 스택의 가장 위의 요소 반환 (제거하지 않음) peek() { if (this.isEmpty()) { return "Stack is empty."; } return this.items[this.items.length - 1]; } // 스택이 비어있는지 여부 확인 isEmpty() { return this.items.l.. 2023. 7. 15. 이전 1 다음 반응형