This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
In [ ]:
%run ../stack/stack.py
%load ../stack/stack.py
In [ ]:
class StackWithCapacity(Stack):
def __init__(self, top=None, capacity=10):
# TODO: Implement me
pass
def push(self, data):
# TODO: Implement me
pass
def pop(self):
# TODO: Implement me
pass
def is_full(self):
# TODO: Implement me
pass
class SetOfStacks(object):
def __init__(self, capacity):
# TODO: Implement me
pass
def push(self, data):
# TODO: Implement me
pass
def pop(self):
# TODO: Implement me
pass
In [ ]:
# %load test_set_of_stacks.py
from nose.tools import assert_equal
class TestSetOfStacks(object):
def test_set_of_stacks(self):
print('Test: Push on an empty stack')
capacity = 2
stacks = SetOfStacks(capacity)
stacks.push(3)
print('Test: Push on a non-empty stack')
stacks.push(5)
print('Test: Push on a capacity stack to create a new one')
stacks.push('a')
print('Test: Pop on a one element stack to destroy it')
assert_equal(stacks.pop(), 'a')
print('Test: Pop general case')
assert_equal(stacks.pop(), 5)
assert_equal(stacks.pop(), 3)
print('Test: Pop on no elements')
assert_equal(stacks.pop(), None)
print('Success: test_set_of_stacks')
def main():
test = TestSetOfStacks()
test.test_set_of_stacks()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.