#pragma once
template <class ty>
class stack
{
public:
stack(int num)
{
this->t = new ty[num];
this->max = num-1;
this->top = -1;
}
void push(ty n)
{
if (this->top == this->max) return;
this->t[++this->top] = n;
return;
}
ty pop()
{
if (this->top != -1)
return this->t[this->top--];
}
bool empty()
{
if (this->top == -1) return true;
return false;
}
~stack()
{
if (this->t != nullptr)
{
this->t = nullptr;
delete this->t;
}
}
ty* t;
int top;
int max;
};
C++自写stack
最新推荐文章于 2023-01-11 11:04:05 发布