#include<iostream>
using namespace std;
template <class T>
class Stack
{
private:
int mSize;
int top;
T *str;
public:
Stack(int mSize)
{
top = -1;
str = new T[mSize];
}
~Stack()
{
delete []str;
}
void clear()
{
top = -1;
}
bool push(T e)
{
if(top == mSize - 1)
{
cout<<"栈满";
return false;
}
else
{
top++;
str[top] = e;
cout<<str[top]<<" ";
return true;
}
}
bool pop()
{
if(top == -1)
{
cout<<"栈为空";
return false;
}
else
{
cout<<str[top]<<" ";
top--;
return true;
}
}
};
int main()
{
Stack<int> list(5);
for(int i = 0;i<5;i++)
{
list.push(i+1);
}
cout<<endl;
for(int i = 0;i<5;i++)
list.pop();
return 0;
}
using namespace std;
template <class T>
class Stack
{
private:
int mSize;
int top;
T *str;
public:
Stack(int mSize)
{
top = -1;
str = new T[mSize];
}
~Stack()
{
delete []str;
}
void clear()
{
top = -1;
}
bool push(T e)
{
if(top == mSize - 1)
{
cout<<"栈满";
return false;
}
else
{
top++;
str[top] = e;
cout<<str[top]<<" ";
return true;
}
}
bool pop()
{
if(top == -1)
{
cout<<"栈为空";
return false;
}
else
{
cout<<str[top]<<" ";
top--;
return true;
}
}
};
int main()
{
Stack<int> list(5);
for(int i = 0;i<5;i++)
{
list.push(i+1);
}
cout<<endl;
for(int i = 0;i<5;i++)
list.pop();
return 0;
}