#include <iostream>
using namespace std;
#define MAX_S 5
//顺序栈
template<typename T>
class Ware
{
private:
//申请空间
T date[MAX_S];
//栈顶
int top;
public:
Ware():date(),top(MAX_S-1){}
void push(T e);
T pop();
void show()
{
for(int i=0;i<=top;i++)
cout<<date[i]<<endl;
}
};
template<typename T>
void Ware<T>::push(T e)
{
if(top==MAX_S-1)
{
cout<<"full"<<endl;
}
else
{
date[top++]= e;
}
}
template<typename T>
T Ware<T>::pop()
{
if(top==-1)
{
cout<<"empty"<<endl;
}
else
{
top--;
return date[date];
}
}
int main()
{
Ware<int> p;
p.push(1);
p.push(2);
p.push(3);
p.show();
return 0;
}
C++day4作业
最新推荐文章于 2024-05-19 16:12:42 发布