생성일: 2021년 10월 8일 오후 5:20
MAX_ITEMS = 100
class QueueType():
def __init__(self):
self.maxQue = MAX_ITEMS + 1
self.info = [0] * self.maxQue
self.front = self.maxQue - 1
self.rear = self.maxQue - 1
def enqueue(self, data):
'''[1]'''
self.rear = (self.rear + 1) % self.maxQue
self.info[self.rear] = data
def dequeue(self):
'''[2]'''
self.front = (self.front + 1) % self.maxQue
return self.info[self.front]
def is_empty(self):
'''[3]'''
return (self.rear == self.front)
def is_full(self):
'''[4]'''
return ((self.rear + 1) % self.maxQue == self.front)
def make_empty(self):
'''[5]'''
self.front = self.maxQue - 1
self.rear = self.maxQue - 1
import os
from QueueType import *
if __name__ == '__main__':
my_queue = QueueType()
for i in range(5):
number = int(input("enter the number: "))
my_queue.enqueue(number)
your_queue = QueueType()
for i in range(5):
number = int(input("enter the number: "))
your_queue.enqueue(number)
print()
print(my_queue.is_full())
print()
while (True):
if (my_queue.is_empty() == True):
break
else:
print(my_queue.dequeue())
print()
print(my_queue.is_full())
print(my_queue.is_empty())
print()
print()
print(your_queue.is_full())
print()
your_queue.make_empty()
print(your_queue.is_full())
print(your_queue.is_empty())