Stack
-
[자료구조] StackData Structure 2022. 9. 17. 17:22
1. stack 이란? 데이터(원소)를 탑 형태로 쌓는 형태의 자료구조. LIFO(Last In First Out)이라고 하며, 가장 마지막에 들어간 원소가 가장 처음으로 나오는 구조이다. stack의 예시는, ctrl + z(실행 취소) , 이전페이지로 가기 등이 있다. 2. stack 의 코드 구현 class Node { constructor(value){ this.value = value; this.next = null; } } class Stack { constructor(){ this.top = null; this.bottom = null; this.length = 0; } peek() { // stack에 쌓인 가장 마지막 녀석을 확인하는 메소드 return this.top; } push(va..