Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Queue
FIFO(First In, First Out)원칙을 따르는 선형 자료구조항상 끝에만 삽입, 항상 앞에서만 조회, 삭제
선입 선출, 발신 순서 그대로 수신해야 하는 경우에 활용
구현
FixedQueue
array로 구현한 고정 크기 queue
양 끝의 두 포인터(first, last)를 순환시키며 처음에 생성한 capacity만큼의 공간을 계속 재사용(포인터 값을 뒤로 이동할 때 마다 모듈러 연산 수행)
시간복잡도
enqueue, dequeue, peek 모두 O(1)
FlexibleQueue
단방향 순환 linked list로 구현한 가변 크기 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)