添加了模板类应用

 /*************************************************************************
> File Name: 05_StackMakeQueue.cpp
> Author: Juntaran
> Mail: [email protected]
> Created Time: 2016年08月29日 星期一 19时32分12秒
************************************************************************/ #include <stdio.h>
#include <bits/stdc++.h> using namespace std; template<class T>
class qStack
{
private:
stack<T> stack1;
stack<T> stack2;
int size; public:
qStack()
{
size = ;
}
void push(T &node)
{
stack1.push(node);
size = stack1.size();
}
T pop()
{
assert(this->size > );
T ret = ;
if (this->size == )
{
ret = stack1.top();
stack1.pop();
this->size = ;
return ret;
}
if (this->size > )
{
while (stack1.size())
{
stack2.push(stack1.top());
stack1.pop();
}
ret = stack2.top();
stack2.pop(); while (stack2.size())
{
stack1.push(stack2.top());
stack2.pop();
}
this->size --;
return ret;
}
}
}; int main()
{
qStack<int> quque;
for (int i = ; i < ; i++)
{
cout << i << " push" << endl;
quque.push(i);
}
for (int i = ; i < ; i++)
{
cout << quque.pop() << " pop" << endl;
}
for (int i = ; i < ; i++)
{
cout << i << " push" << endl;
quque.push(i);
}
for (int i = ; i < ; i++)
{
cout << quque.pop() << " pop" << endl;
}
cout << endl;
}
05-10 23:30