数据结构:栈的实现
来源:互联网 发布:淘宝手机首页尺寸 编辑:程序博客网 时间:2024/05/22 02:31
using namespace std;
class Stack
{
private:
int maxSize;
int top;
int theArray[100];
public:
Stack(int capacity)
{
maxSize = capacity;
top = -1;
int x;
cin>>x;
int i = 0;
while(x != 0)
{
theArray[++top] = x;
cin>>x;
}
}
bool isEmpty()
{
return top == -1;
}
bool isFull()
{
return top == maxSize - 1;
}
void push(int x)
{
if(isFull())
cout<<"push failed,the stack is full"<<endl;
else
{
theArray[++top] = x;
}
}
void pop()
{
if(isEmpty())
cout<<"pop failed,the stack is empty"<<endl;
else
{
top--;
}
}
int topAndPop()
{
if(isEmpty())
cout<<"top and pop failed,the stack is empty"<<endl;
else
{
return theArray[top - 1];
top--;
}
}
int Top()
{
if(isEmpty())
cout<<"top failed,the stack is empty"<<endl;
else
return theArray[top];
}
void outputStack()
{
if(isEmpty())
cout<<"output failed,the stack is empty"<<endl;
else
{
for(int i = 0;i <= top;i ++)
{
cout<<theArray[i]<<" ";
}
}
}
};
- 数据结构 --栈的实现
- 数据结构:栈的实现
- 数据结构-----栈的实现
- 数据结构-----栈的实现
- 【数据结构】栈的实现
- 数据结构-栈的实现
- 数据结构,关于栈的实现
- Java 数据结构----栈的实现
- 数据结构中栈的实现
- Java数据结构--栈的实现
- 数据结构之栈的实现
- 数据结构-链式栈的实现
- 数据结构 一、栈的实现
- 【数据结构】栈-数组的实现
- [数据结构] 栈的数组实现
- [数据结构] 栈的指针实现
- 数据结构栈的C++实现
- 表达式--栈的实现(数据结构)
- 数据结构:队列的实现
- Oracle 分组 + 行转列操作
- Flash3D Away3D 4.0教程
- 博弈小结
- linux排序去重比较
- 数据结构:栈的实现
- ARM与X86架构对比区别
- xml特殊字符处理 如&
- ffmpeg原来还可以转换图片格式
- with as 简介
- fopen函数的几种模式说明
- Xcode4.2开发入门之一些变化
- IIS7运行.NET Framework 4 报500错误 404 错误
- Return Top