Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- swift알고리즘
- Content Hugging priority
- OperationQueue
- 알고리즘
- Union-Find
- 동작과정
- AI
- gitlabci/cd
- CICD
- CI/CD
- 백준
- IOS
- Autolayout
- mvvm
- 자료구조
- apple intelligence
- gitlab
- Content Compression Resistance priority
- swift
- ReactiveX
- 동시성프로그래밍
- RxSwift요약
- 애플인텔리전스
- ai expo
- 클린아키텍처
- RxCocoa
- 오토레이아웃
- rxswift
- LLM
- cleanarchitecture
Archives
- Today
- Total
JosephCha의 개발일지
큐 본문
정의
- 줄을 서는 행위와 유사
- 가장 먼저 넣은 데이터를 가장 먼저 꺼낼 수 있는 구조
- 음식점에서 가장 먼저 줄을 선 사람이 제일 먼저 음식점에 입장하는 것과 동일
참고
- Enqueue: 큐에 데이터를 넣는 기능
- Dequeue: 큐에서 데이터를 꺼내는 기능
struct Queue<T> {
private var queue: [T?] = []
private var head: Int = 0
public var count: Int {
return queue.count
}
public var isEmpty: Bool {
return queue.isEmpty
}
public mutating func enqueue(_ element: T) {
queue.append(element)
}
public mutating func dequeue() -> T? {
guard head <= queue.count, let element = queue[head] else { return nil }
queue[head] = nil
head += 1
if head > 50 {
queue.removeFirst(head)
head = 0
}
return element
}
}
코드 참고: https://babbab2.tistory.com/84?category=908011
'알고리즘 및 자료구조' 카테고리의 다른 글
[브루트 포스]백준/2798번/블랙잭 (0) | 2022.07.26 |
---|---|
백준/2920번/음계 문제 (0) | 2022.07.26 |
스택 (0) | 2022.04.20 |
이진탐색 (0) | 2022.04.20 |
병합정렬 (0) | 2022.04.20 |
Comments