선형 자료구조의 일종. First In First Out(FIFO) 방식으로, 먼저 들어간(enqueue) 원소가 먼저 나온다.(dequeue)
뉘여진 원형 통로를 떠올리면는 쉽다. 왼쪽으로 들어간 원소는 오른쪽으로 빠져나오듯 먼저 들어간 원소가 먼저 나온다.
선형 자료구조의 일종. Last In First Out (LIFO) 방식으로, 나중에 들어온(push) 원소가 먼저 나온다.(pop)
public struct Queue<T> {
fileprivate var list = LinkedList<T>()
public mutating func enqueue(_ element: T) {
list.append(value: element)
}
public mutating func dequeue() -> T? {
guard !list.isEmpty, let element = list.first else {return nil}
list.remove(node: element)
return element.value
}
public mutating func peek() -> T? {
return list.first?.value
}
public mutating func isEmpty() -> Bool {
return list.isEmpty
}
}