Skip to content

feat: Queue 구현 - #3

Merged
YJGwon merged 7 commits into
mainfrom
queue
Aug 30, 2023
Merged

YJGwon merged 7 commits into
mainfrom
queue

Conversation

@YJGwon

@YJGwon YJGwon commented Aug 30, 2023

Copy link
Copy Markdown
Owner

Queue

FIFO(First In, First Out) 원칙을 따르는 선형 자료구조
항상 끝에만 삽입, 항상 앞에서만 조회, 삭제
선입 선출, 발신 순서 그대로 수신해야 하는 경우에 활용

  • 프린터 대기열
  • 너비 우선 탐색
  • 주문 대기열
  • Streaming
  • Messaging

구현

FixedQueue

array로 구현한 고정 크기 queue

fixed_queue

양 끝의 두 포인터(first, last)를 순환시키며 처음에 생성한 capacity만큼의 공간을 계속 재사용(포인터 값을 뒤로 이동할 때 마다 모듈러 연산 수행)

시간복잡도

enqueue, dequeue, peek 모두 O(1)

FlexibleQueue

단방향 순환 linked list로 구현한 가변 크기 queue

flexible queue

각 node는 자신의 next만 알고 있고, queue는 tail node를 참조 (tail을 알면 tail.next로 head까지 알 수 있음)
queue가 비어있을 때는 tail이 static singleton 객체인 empty node를 참조
그렇지 않을 때에는 head -> ... -> tail -> head 와 같이 단방향 circular linked list 형태

시간복잡도

enqueue, dequeue, peek 모두 O(1)

@YJGwon
YJGwon merged commit 08bfd32 into main Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant