import queue // first in first out data_queue = queue.Queue() data_queue.put("testqueue") data_queue.put(11) data_queue.put(22) data_queue.qsize() // 3 data_queue.get() // 'testqueue' data_queue.get() // 11 data_queue.get() // 12 data_queue.qsize() // 0 // last in first out data_listqueue = queue.LifoQueue() data_listqueue .put("testlistqueue") data_listqueue .put(1) data_listqueue.qsize() // 2 data_listqueue.get() // 1 // 우선순위 지정 리스트 data_priorityqueue = queue.PriorityQueue() data_priorityqueue .put((10, "korea")) data_priorityqueue .put((5, 1)) data_priorityqueue .put((15, "china")) data_priorityqueue .qsize() // 3 data_priorityqueue .get() // 5, 1 data_priorityqueue .get() // korea // enqueue, dequeue 기능 구현 queue_list = list() def enqueue(data): queue_list.append(data) def dequeue(): data = queue_list[0] del queue_list[0] return data for index in range(10): enqueue(index) len(queue_list) // 10 dequeue() // 0 | cs |
::public/Python