[자료구조] Ch6. Queues

김규원·2024년 3월 21일
0

자료구조

목록 보기
7/14
post-thumbnail

The Queue ADT

  • enqueue(object)
  • object dequeue()
  • object first()
  • integer len()
  • boolean is_empty()

FIFO(First In First Out)

ex. 은행창구 번호표

Array-based Queue

  • f index of the from element
  • r index immediately past the rear element

Queue Operations

size(), isEmpty()

enqueue(o)

dequeue()

Queue in python

_data
_size
_front

class ArrayQueue:
	DEFAULT_CAPACITY = 10
    
    def __init__(self):
    	self._data = [None] * ArrayQueue.DEFAULT_CAPACITY
        self._size = 0
        self._front = 0
        
    def __len__(self):
    	return self._size
        
    def is_empty(self):
    	return self._size == 0
        
    def first(self):
    	if self.is_empty():
        	raise Empty('Queue is empty')
        return self._data[self._front]
    def dequeue(self):
    	if self.is_empty():
        	raise Empty('Queue is empty')
            answer = self._data[self._front]
            self._data[self._front] = None
            self._front = (self._front + 1) % len(self._data)
            self._size -= 1
            return answer
    .
    
    .
    .

profile
행복한 하루 보내세요

0개의 댓글