Stack은 후입선출(Last In First Out)이다.
class MyStack:
def __init__(self):
self.plate = []
def push(self, value):
self.plate.append(value)
def pop(self):
if len(self.plate)==0:
return "It's already empty!"
else:
self.plate.pop()
def is_empty(self):
return len(self.plate) == 0
def peak(self):
return self.plate[-1]
def print_stack(self):
print(self.plate)
Queue는 선입선출(First In First Out)이다.
class MyQueue:
def __init__(self):
self.waiting = []
def enqueue(self, value):
self.waiting.append(value)
def dequeue(self):
self.waiting.pop(0)
def front(self):
return self.waiting[0]
def is_empty(self):
return len(self.waiting)==0
def print_queue(self):
print(self.waiting)