Set of Stack data structure with threshold
Problem:
Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOfStacks should be composed of several stacks, and should create a new stack once the previous one exceeds capacity. SetOfStacks push() and SetOfStacks pop() should behave identically to a single stack (that is, pop() should return the same values as it would if there were just a single stack).
Solution:
I use a vector of stacks for implementing this data structure. During push I make sure size of individual stacks doesn't exceed the threshold and during pop I make sure empty stacks are erased from the vector. C++ implementation follows:
https://gist.github.com/nirvana-attained/7197052













