1 #include2 #include 3 using namespace std; 4 5 template class SQueue 6 { 7 public: 8 SQueue():cnt(0){}; 9 10 void push(const T& node);11 T pop();12 int getSize();13 14 private:15 stack pushstack;16 stack popstack;17 18 int cnt;19 };20 21 template void SQueue ::push(const T& node)22 {23 pushstack.push(node);24 25 cnt++;26 }27 28 template T SQueue ::pop()29 {30 if(popstack.empty())31 {32 while(!pushstack.empty())33 {34 T tmp = pushstack.top();35 pushstack.pop();36 popstack.push(tmp);37 }38 }39 40 if(popstack.empty())41 {42 throw new exception();43 }44 45 T ret = popstack.top();46 popstack.pop();47 48 cnt--;49 50 return ret;51 }52 53 template int SQueue ::getSize()54 {55 return cnt;56 }57 58 int main()59 {60 SQueue Queue;61 Queue.push(1);62 Queue.push(2);63 Queue.push(3);64 65 cout<<"currnet size:"< <