1. 구조

  • 줄을 서는 것과 비슷함
  • 가장 먼저 들어간 데이터는 가장 먼저 나오는 구조
  • FIFO(First-in, First-Out) 또는 LILO(Last-in, Last-out) 방식

2. 용어

  • Enqueue : 큐에 데이터 넣는 기능
  • Dequeue : 큐에서 데이터를 꺼내는 기능

3. 소스코드

리스트 변수로 큐의 enqueue, dequeue 기능 구현

# queueList : list 변수
queueList = list()

# enqueue
def enqueue(data):
    queue_list.append(data)

# dequeue
def dequeue():
    data = queue_list[0]
    del queue_list[0]
    return data
사용된 것
  1. array.append(x)배열 끝에 값 x를 추가합니다.
  2. Append a new item with value x to the end of the array.
  3. del
  4. 예약어
  5. return현재 함수가 반환될 때까지 실행을 계속합니다.
  6. Continue execution until the current function returns.

'Algorithm' 카테고리의 다른 글

[Algorithm] 배열 (Array)  (0) 2021.08.25

+ Recent posts