concept/data structure

Data structure : 자료구조 (stack, queue)

오연 : Oana 2020. 5. 2. 18:48

 

stack

 

 

 

Last in First out (후입선출)

 

 

 구조예시 

책상 위에 쌓아둔 책

주방에 쌓아둔 접시

하노이의 탑

 

 

 활용 예 

웹브라우저 방문기록(뒤로가기)

실행취소

 

 

 자바스크립트에서 지원하는 다양한 stack method들이 있다. 

  • pop — Pulls (removes) the element out of the stack. ...

  • push — Pushes (inserts) the element in the stack. ...

  • peek — returns the item on the top of the stack, without removing it.

  • empty — returns true if the stack is empty, false otherwise.

  • swap — the two top most elements of the stack can be swapped.

 

 

 

queue

 

 

First in First out (선입선출)

 

 구조 예시 

놀이동산에서 줄서서 기다리는 것

은행에서 번호표 뽑은 순서대로 일을 처리하는 것

 

 

 활용 예 

게임대전시스템

 

 

 자바스크립트에서 지원하는 다양한 queue method들이 있다. 

  • enqueue(item) : Remove the top item from the queue.

  • dequeue() : Add an item to the top of the queue.

  • peek() : Return the item at the top of the queue.

  • isEmpty() : Returns true if the queue is empty.

 

 

ADVANCED

* 힙트리

* 선형큐 vs 원형큐