연결 리스트
-
[알고리즘 개념] 스택/큐알고리즘 공부/알고리즘 개념 2020. 8. 9. 12:07
스택 그림을 보면 알 수 있듯, 스택은 LIFO(Last In Frist Out) 후입 선출 구조이다. 즉, 밑이 막힌 구조로 마지막으로 넣은 것이 먼저 나온다는 것이다. 쉽게 생각하면 쌓아 올린 접시를 생각하면 된다. 실생활에서는 컴퓨터의 뒤로 가기 기능이 스택을 이용하여 구현되었다. 페이지 뒤로 가기, 실행 취소 (Ctrl + Z)와 같은 기능은 스택의 대표 예제이다. 데이터를 삽입할 때는 push 데이터를 삭제할 때는 pop이라는 용어를 사용한다. 스택에서는 마지막 데이터 위치를 기억하기 위해 top이라는 변수를 사용하여 구현하게 된다. 스택 구현은 배열과 연결 리스트를 통해 구현할 수 있다. 배열의 장점은 구현이 쉽고, 원하는 데이터의 접근 속도가 빠르다는 것이다. 하지만, 배열의 크기가 정해져 ..