1 #include <iostream> 2 #include <queue> 3 #include <climits> 4 #include <algorithm> 5 #include <memory.h> 6 #include <stdio.h> 7 #include <ostream> 8 #include <vector> 9 #include <list> 10 #include <cmath> 11 #include <string> 12 #include <stdexcept> 13 #include <stack> 14 using namespace std; 15 16 template<typename T> 17 class SetOfStacks 18 { 19 vector<stack<T> > stacks; 20 int stackSize; 21 public: 22 SetOfStacks(int paramStackSize):stackSize(paramStackSize) 23 { 24 25 } 26 void push(const T&elem) 27 { 28 if(stacks.size() == 0) 29 { 30 stack<T> tmp; 31 tmp.push(elem); 32 stacks.push_back(tmp); 33 return; 34 } 35 if(stacks[stacks.size()-1].size() == stackSize) 36 { 37 stack<T> tmp; 38 tmp.push(elem); 39 stacks.push_back(tmp); 40 } 41 else 42 { 43 stacks[stacks.size()-1].push(elem); 44 } 45 } 46 T pop() 47 { 48 if(stacks.size() == 0) 49 throw std::out_of_range("stacks is empty"); 50 T val = stacks[stacks.size()-1].top(); 51 stacks[stacks.size()-1].pop(); 52 if(stacks[stacks.size()-1].size() = 0) 53 stacks.pop_back(); 54 return val; 55 } 56 }; 57 58 int main() 59 { 60 SetOfStacks<int> s(1); 61 s.push(1); 62 s.push(2); 63 64 return 0; 65 }