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