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 |
Tags
- modern concurrency
- WWDC
- 오블완
- SWIFT
- APNS
- ios
- 티스토리챌린지
- modern concurrency deep dive
- 야곰 # 야곰아카데미커리어스타터캠프 #iOS개발자 # 부트캠프
Archives
- Today
- Total
Geon
큐[BOJ] 본문
코드
import Foundation
struct Queue {
private var list: [Int] = []
mutating func push(value: Int) {
list.append(value)
}
mutating func pop() -> Int{
list.isEmpty ? -1 : list.removeFirst()
}
func size() -> Int {
return list.count
}
func empty() -> Int {
return list.isEmpty ? 1 : 0
}
func front() -> Int {
return list.first ?? -1
}
func back() -> Int {
return list.last ?? -1
}
}
var queue = Queue()
for _ in 0..<Int(readLine()!)! {
let commnad = readLine()!.split(separator: " ")
switch commnad[0] {
case "push":
queue.push(value: Int(commnad[1])!)
case "front":
print(queue.front())
case "back":
print(queue.back())
case "size":
print(queue.size())
case "pop":
print(queue.pop())
case "empty":
print(queue.empty())
default:
break
}
}
'코딩테스트' 카테고리의 다른 글
OddOccurrencesInArray (0) | 2022.05.13 |
---|---|
요세푸스 문제[BOJ] (0) | 2022.03.26 |
괄호[BOJ] (0) | 2022.03.22 |
단어뒤집기[BOJ] (0) | 2022.03.22 |
스택[BOJ] (0) | 2022.03.22 |