-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack.py
39 lines (30 loc) · 1.04 KB
/
stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Stack:
containers = []
column = 0
max_height = 0
def __init__(self, column, max_height):
self.column = column
self.max_height = max_height
self.containers = []
def pop(self):
return self.containers.pop()
def get_max_height(self):
return self.max_height
def get_height(self):
return len(self.containers)
def push(self, container):
if len(self.containers) < self.max_height:
self.containers.append(container)
else:
raise IndexError("Can only stack containers up to %s high in current area" % (self.max_height))
def peek(self):
return self.containers[-1] if len(self.containers) != 0 else None
def get_column(self):
return self.column
def __repr__(self):
return "[Column: %s, Height: %s, Contents: %s]" % (self.column, self.get_height(), self.containers)
def has(self, containers):
for i in containers:
if i in self.containers:
return True
return False