[알고리즘] 큐, 덱 - 백준 10866번 덱
정답 코드
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
arr = deque()
for _ in range(N):
    val = input().split()
    if val[0] == 'push_front':
        arr.appendleft(val[1])
    elif val[0] == 'push_back':
        arr.append(val[1])
    elif val[0] == 'pop_front':
        if arr: print(arr.popleft())
        else:   print(-1)
    elif val[0] == 'pop_back':
        if arr: print(arr.pop())
        else:   print(-1)
    elif val[0] == 'size':
        print(len(arr))
    elif val[0] == 'empty':
        if not arr: print(1)
        else:   print(0)
    elif val[0] == 'front':
        if arr: print(arr[0])
        else:   print(-1)
    elif val[0] == 'back':
        if arr: print(arr[-1])
        else:   print(-1)
덱, 데크 (Deque)
양쪽에서 모두 삽입/인출이 가능한 스택과 큐의 특징을 모두 갖고 있는 자료구조

( 출처 : 큐(자료구조) 나무위키 )
Author And Source
이 문제에 관하여([알고리즘] 큐, 덱 - 백준 10866번 덱), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@minidoo/알고리즘-큐-덱-백준-10866번-덱저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)