> 자료구조 구현/큐2 enqueue, dequeue 직접 구현하기 list로 enqueue, dequeue 구현하기 12345678910111213141516171819q_list = list() def enqueue(data): q_list.append(data) def dequeue(): data = q_list[0] del q_list[0] return data for i in range(10): enqueue(i) # size: 10len(q_list) # 0..9for i in range(10): print(dequeue())cs 2020. 9. 15. import queue 사용하기 FIFO(First-In, First-Out) import queue q = queue.Queue() q.put(1) q.put("Sky") q.put(True) # size: 3 print(q.qsize()) # 1, Sky, True for i in range(q.qsize()): print(q.get()) LIFO(Last-In, First-Out) import queue lifo_q = queue.LifoQueue() lifo_q.put("1") lifo_q.put("Air") lifo_q.put("True") # size: 3 print(lifo_q.qsize()) # True, Air, 1 for i in range(lifo_q.qsize()): print(lifo_q.get()) Prio.. 2020. 9. 15. 이전 1 다음