stack1顺序栈
2024-09-05 22:54:35
顺序栈 #include<iostream>
using namespace std;
#define increasesize 10 template <class Object>
class Stack
{
public:
explicit Stack (int capacity = 10)
{
theArray = new Object[capacity];
MaxSize = capacity;
top = -1;
}
bool isEmpty() const
{
return top == -1;
}
bool isFull() const
{
return top == MaxSize -1;
}
const Object & Top() const
{
if(isEmpty()) throw Underflow();
return theArray[top];
}
void makeEmpty()
{
top = -1;
}
void Pop()
{
if(isEmpty()) throw Underflow();
cout<<theArray[top];
top -- ;
}
Object Push(const Object & x)
{
if(isFull())throw Overflow();
theArray [++top] = x;
}
Object topAndpop()
{
if(isEmpty()) throw Underflow();
}
int Underflow()
{
cout<<"underflow"<<endl;
return -1;
}
int Overflow()
{
cout << "overflow" <<endl;
return -1;
}
private:
int MaxSize;
int top;
Object * theArray;
};
int main()
{
Stack <int> dusk;
for(int i = 0 ; i < 10 ; i++)
{
dusk.Push(i);
}
for(int i = 0 ; i < 10 ; i++)
{
dusk.Pop();
}
} //template <class T>
//void dusk<T>::hanshu(T x)
//{}
最新文章
- java并发编程(九)死锁
- if 语句运用
- mysql 日期对比,varchar类型装换为datetime类型
- Linux永久修改系统时间和时区方法
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter作用
- Java自定义日志输出文件
- Hadoop中两表JOIN的处理方法
- [三]SpringMvc学习-封装、乱码问题、重定向、转发
- firefox-Developer开发者站点——关于Object.create()新方法的介绍
- java线程的等待、通知机制【读书笔记】
- mysql CMD命令
- c# winform多线程实时更新控件
- Python高级特性:切片
- CRM WEB UI 01 BOL向导创建的搜索
- MES制造执行系统
- Android开发-- 使用ADT23 的一些问题
- 用Nodejs连接MySQL(原文链接)
- ASCII码表(0-127 ) C中的转义字符
- JS字符串相关操作
- Metasploit域渗透测试全程实录(终结篇)