栈顺序存储结构的C++模板类程序源代码

栈顺序存储结构利用一个大数组,相当于简化了的线性表,线性表具有查找、插入、删除等功能,而栈则简化为只包括压入、弹出这种更有针对性的功能。下面是自己写的栈的顺序存储C++模板类源代码:

//linearstack.h
#ifndef LINEARSTACK
#define LINEARSTACK
#include <IOSTREAM>
const int ROOMSIZE=100;
template<class Type>
class LinearStack
{
private:
Type Data[ROOMSIZE];
int top;
public:
LinearStack():top(0){};
~LinearStack(){};
bool Push(Type temp);
Type Pop();
bool IsFull();
bool IsEmpty();
void Print();
};
template<class Type>
bool LinearStack<Type>::Push(Type temp)
{
if(IsFull())
return false;
Data[top++]=temp;
return true;
}
template<class Type>
Type LinearStack<Type>::Pop()
{
if(IsEmpty())
return Type(-111);
top--;
return Data[top];
}
template<class Type>
bool LinearStack<Type>::IsFull()
{
if(top==ROOMSIZE)
return true;
else
return false;
}
template<class Type>
bool LinearStack<Type>::IsEmpty()
{
if(top==0)
{
return true; 
}
else
return false;
}
template<class Type>
void LinearStack<Type>::Print()
{
for(int i=0;i<top;i++)
{
std::cout<<Data[i]<<" ";
}
std::cout<<std::endl;
}
#endif

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值