Queue

  • FIFO(First In, First Out)
  • 선입선출
  • 먼저 들어온 것이 먼저 나가는 방식

    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
    class Queue:
    def __init__(self):
    self.container = list()

    def empty(self):
    if self.container:
    return False
    else:
    return True

    def enqueue(self, data):
    return self.container.append(data)

    def dequeue(self):
    return self.container.pop(0)

    def peek(self):
    return self.container[0]


    if __name__ == '__main__':

    que = Queue()

    for i in range(1, 6):
    que.enqueue(i)

    while not que.empty():
    print(que.dequeue(), end = " ")

    >> 1 2 3 4 5
Share