Data Structure(자료 구조) - Stack & Queue
cd(Change Directory), pwd(현재 경로를 알아보는 명령어)
class Stack {
constructor() {
this.state = [];
}
push = (data) => {
// 데이터를 스택에 push 하는 것을 구현 해 주세요
this.state.push(data);
};
pop = () => {
// 데이터를 스택에서 pop 해서 그 값을 리턴하도록 구현 해 주세요
return this.state.pop();
};
getPeak = () => {
// 스택의 최상위 값을 리턴하도록 구현 해 주세요
return this.state[this.state.length - 1];
};
}
module.exports = Stack;
class Queue {
constructor() {
// 어떤 자료구조를 사용해 데이터를 담아야 할지 고민 해 주세요
this.state = [];
}
enqueue = (data) => {
// 데이터를 큐에 enqueue 하는 것을 구현 해 주세요
this.state.push(data);
};
dequeue = () => {
// 데이터를 큐에서 dequeue 해서 그 값을 리턴하도록 구현 해 주세요
return this.state.shift();
};
getFirst = () => {
// 큐의 가장 먼저 들어온 값을 리턴하도록 구현 해 주세요
return this.state[0];
};
}
module.exports = Queue;