顺序栈的基本操作code_legend
来源:互联网 发布:微商是什么软件 编辑:程序博客网 时间:2024/06/07 06:35
#include <iostream>
using namespace std;
typedef int elemType;
//#definde Maxsize 10
class seqStack{
public :
int maxSize;
int top;
elemType * array;
public :
/*init the stack*/
void initStack(int maxsize){
this->maxSize=maxsize;
this->array=new elemType[maxSize];
this->top=-1;
}
/*constructor*/
seqStack(int maxsize){
this->initStack(maxsize);
}
/*destrucotr*/
~seqStack(){
delete []array;
}
/*is full?*/
bool isStackFull(){
if(this->top==this->maxSize-1)
return true;
else
return false;
}
/*is empty?*/
bool isStackEmpty(){
if(this->top==-1)
return true;
else
return false;
}
/*push the element into the stack,
if the stack is full ,return fasle;
else return true;
*/
bool push(elemType element){
if(this->isStackFull())
return false;
this->top++;
this->array[this->top]=element;
return true;
}
/*
pop the top element from the stack;
if the stack is empty ,return false;
else return true.
*/
bool pop(elemType& topElement){
if(this->isStackEmpty())
return false;
topElement=this->array[this->top];
this->top--;
return true;
}
/*get the current size of the stack */
int getSize(){
return this->top+1;
}
/*get the top element
if the stack is empty ,return false ;
else true;
*/
bool getTop(elemType& topElement){
if(this->isStackEmpty())
return false;
topElement=this->array[this->top];
return true;
}
};
int main()
{
seqStack seqstack(10);
seqstack.push(2);
seqstack.push(3);
seqstack.push(4);
elemType element;
int size;
cout<<"push 2 , 3, 4"<<endl;
size=seqstack.getSize();
cout<<"size is : "<<size<<endl;
seqstack.pop(element);
cout<<"pop the top , top is : "<<element<<endl;
size=seqstack.getSize();
cout<<"size is : "<<size<<endl;
seqstack.getTop(element);
cout<<"get the top is :"<<element<<endl;
cout << "Hello world!" << endl;
return 0;
}
using namespace std;
typedef int elemType;
//#definde Maxsize 10
class seqStack{
public :
int maxSize;
int top;
elemType * array;
public :
/*init the stack*/
void initStack(int maxsize){
this->maxSize=maxsize;
this->array=new elemType[maxSize];
this->top=-1;
}
/*constructor*/
seqStack(int maxsize){
this->initStack(maxsize);
}
/*destrucotr*/
~seqStack(){
delete []array;
}
/*is full?*/
bool isStackFull(){
if(this->top==this->maxSize-1)
return true;
else
return false;
}
/*is empty?*/
bool isStackEmpty(){
if(this->top==-1)
return true;
else
return false;
}
/*push the element into the stack,
if the stack is full ,return fasle;
else return true;
*/
bool push(elemType element){
if(this->isStackFull())
return false;
this->top++;
this->array[this->top]=element;
return true;
}
/*
pop the top element from the stack;
if the stack is empty ,return false;
else return true.
*/
bool pop(elemType& topElement){
if(this->isStackEmpty())
return false;
topElement=this->array[this->top];
this->top--;
return true;
}
/*get the current size of the stack */
int getSize(){
return this->top+1;
}
/*get the top element
if the stack is empty ,return false ;
else true;
*/
bool getTop(elemType& topElement){
if(this->isStackEmpty())
return false;
topElement=this->array[this->top];
return true;
}
};
int main()
{
seqStack seqstack(10);
seqstack.push(2);
seqstack.push(3);
seqstack.push(4);
elemType element;
int size;
cout<<"push 2 , 3, 4"<<endl;
size=seqstack.getSize();
cout<<"size is : "<<size<<endl;
seqstack.pop(element);
cout<<"pop the top , top is : "<<element<<endl;
size=seqstack.getSize();
cout<<"size is : "<<size<<endl;
seqstack.getTop(element);
cout<<"get the top is :"<<element<<endl;
cout << "Hello world!" << endl;
return 0;
}
0 0
- 顺序栈的基本操作code_legend
- 链式栈的基本操作code_legend
- 共享栈的基本操作code_legend
- 链式队列基本操作之code_legend
- 顺序栈的基本操作
- 顺序栈的基本操作....
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- 顺序栈的基本操作
- Java Math的 floor,round和ceil的总结
- Android Bitmap 全面解析(四)图片处理效果对比 ...
- app itunes 文件共享
- iStylePDF vb版示例
- android UI设计时需要注意遵循的设计原则
- 顺序栈的基本操作code_legend
- 去除HTML标签
- 主宰全球的10大算法
- Android or java https ssl exception
- 对Unity Editor 控件的封装 (4.3.2f1)
- 列表、集合与数组之间的转化
- Thrift框架介绍
- 黑马程序员-----JAVA查找文件,复制到指定的文件夹
- system 权限读取注册表HKEY_CURRENT_USER