-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ3_StackPlates.py
40 lines (32 loc) · 1 KB
/
Q3_StackPlates.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
40
# Created by Elshad Karimov on 02/06/2020.
# Copyright © 2020 AppMillers. All rights reserved.
# Stack of Plates
class PlateStack():
def __init__(self, capacity):
self.capacity = capacity
self.stacks = []
def __str__(self):
return self.stacks
def push(self, item):
if len(self.stacks) > 0 and (len(self.stacks[-1])) < self.capacity:
self.stacks[-1].append(item)
else:
self.stacks.append([item])
def pop(self):
while len(self.stacks) and len(self.stacks[-1]) == 0:
self.stacks.pop()
if len(self.stacks) == 0:
return None
else:
return self.stacks[-1].pop()
def pop_at(self, stackNumber):
if len(self.stacks[stackNumber]) > 0:
return self.stacks[stackNumber].pop()
else:
return None
customStack= PlateStack(2)
customStack.push(1)
customStack.push(2)
customStack.push(3)
customStack.push(4)
print(customStack.pop_at(1))