'자료구조 정리 노트' 시리즈는 자료구조를 공부하면서 그려본 그림들과 함께 간략하게 배운 내용을 공유해 보는 시리즈 입니다.
1. Stack📚
definition of stack
real life applications of stack
- 쌓여있는 책, 동전으로 쌓은 탑
- 웹페이지의 뒤로 가기 기능
stack as an ADT(Abstract Data Type)
Primery Stack Operations
- push(data) : 스텍에 데이터를 삽입
- pop() : 가장 마지막에 삽입된 데이터를 삭제
Secondary Stack Operations
- top() : 가장 마지막에 삽입된 데이터를 삭제 없이 반환
- size() : 스텍에 삽입된 데이터의 수를 반환
- isEmpty() : 스텍에 삽입된 데이터가 없으면 true를 반환하고 그렇지 않으면 false를 반환한다.
Array Implementation of stack (JavaScript)
const Stack = function () {
const arr = [];
this.push = (value) => {
arr.push(value);
};
this.pop = () => {
return arr.pop();
};
this.size = () => {
return arr.length;
};
this.top = () => {
const lastIndex = this.size() - 1;
return arr[lastIndex]
};
this.isEmpty = () => {
const size = this.size();
return (!size) ? true : false;
}
};
📚참고 자료
https://www.youtube.com/watch?v=I37kGX-nZEI
Data Structures and Algorithms with JavaScript: Bringing classic computing approaches to the Web - 맥 밀란