데이터 구조 및 분석 ch_3_6 Queue
Jul 17, 2021
»
writing
KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다
ch_3_6 Queue
Stack
1. Queue : A sceenario of a production line at a factory 2. Structure of Queue : linear like linked lists - A variation of singly linked list : Difference - Boluntarily giving up - Access to the middle in the linked list == Same to the stacks - Only accesses to the first and the last instances in the list - The first instance in the list = The front instance in the queue - The last instance in the list = The rear instance in the queue - An item is inserted at the last - An item is removed at the front - is called Fast-In-First-Out (FIFO) 3. Operation of Queue : Enqueue = Insert an instance at the last in the linked list = Put an instance at the rear in the queue : Dequeue = Remove and return an instance at the first in the linked list = Remove and return an instance at the front in the queue 4. Implementation of Queue : Python code of a queue - Utilizing a singly linked list (I retrieval count) - To dequeue an instance (I retrieval count)
from edu.kaist.seslab.ie362.week3.SinglyLinkedList import SinglyLinkedList
class Queue(object) :
lstInstance = SinglyLinkedList()
def Enqueue(self):
return self.lstInstance.removeAt(0)
def Dequeue(self):
self.lstInstance.insertAt(value, self.lstInstance.geteSize())
queue = Queue()
queue.enqueue('a')
queue.enqueue('b')
queue.enqueue('c')
print(queue.dequeue())
print(queue.dequeue())
print(queue.dequeue())
# a
# b
# c