//顺序栈的实现
/*#include<iostream>
#define STACKlength 100
#define ADD 10
#define ERROR 0
#define TRUE 1
using namespace std;
class SX_Stack
{
private:
int *base;
int top;
int stacklength;
public:
SX_Stack(int n=STACKlength)
{
base=new int [n];
//if(base==NULL)return ERROR;因为用了构造函数,所以没有返回值
top=-1;
stacklength=n;
//return TRUE;
}
void DestorySX_Stack() //销毁栈
{
if(stacklength) delete [] base;
}
void ClearSX_Stack() //将栈清空
{
top=-1;
}
int SX_StackEmpty() //检测栈是否为空
{
if(top==-1){cout<<"The stack is null!"<<endl;return TRUE;}
else
return ERROR;
}
int GetTop(int e) //返回栈顶元素
{
e=base[0];
return TRUE;
}
int Push(int e) //进栈
{
if(top==stacklength-1)
{
int *temp,i;
temp=new int[stacklength+ADD];
if(temp==NULL)return ERROR;
for(i=0;i<stacklength;i++)
temp[i]=base[i];
delete [] base;
base=temp;
stacklength=stacklength+ADD;
}
top++;
base[top]=e;
return TRUE;
}
int Out(int e) //出栈
{
if(top==-1)return ERROR;
e=base[top];
top--;
return e;
}
int Length()
{
return (top+1);
}
void output()
{
if(top==-1){cout<<"The SX_Stack is null!"<<endl;return;}
cout<<"The length of the SX_Stack is:"<<Length()<<endl;
cout<<"The content of the SX_Stack is:";
for(;top>=0;top--)
cout<<base[top]<<" ";
cout<<endl;
}
};
int main()
{
SX_Stack a;
while(!a.SX_StackEmpty())
{
a.ClearSX_Stack();
}
for(int i=0;i<5;i++)
a.Push(i);
a.output();
return 0;
}*/
//顺序栈的数制转换
/*#include<iostream>
#define STACKlength 100
#define ADD 10
#define ERROR 0
#define TRUE 1
using namespace std;
class SX_Stack
{
private:
int *base;
int top;
int stacklength;
public:
SX_Stack(int n=STACKlength)
{
base=new int [n];
//if(base==NULL)return ERROR;因为用了构造函数,所以没有返回值
top=-1;
stacklength=n;
//return TRUE;
}
void DestorySX_Stack() //销毁栈
{
if(stacklength) delete [] base;
}
void ClearSX_Stack() //将栈清空
{
top=-1;
}
int SX_StackEmpty() //检测栈是否为空
{
if(top==-1){cout<<"The stack is null!"<<endl;return TRUE;}
else
return ERROR;
}
int GetTop(int e) //返回栈顶元素
{
e=base[0];
return TRUE;
}
int Push(int e) //进栈
{
if(top==stacklength-1)
{
int *temp,i;
temp=new int[stacklength+ADD];
if(temp==NULL)return ERROR;
for(i=0;i<stacklength;i++)
temp[i]=base[i];
delete [] base;
base=temp;
stacklength=stacklength+ADD;
}
top++;
base[top]=e;
return TRUE;
}
int Out(int e) //出栈
{
if(top==-1)return ERROR;
e=base[top];
top--;
return e;
}
int Length()
{
return (top+1);
}
void output()
{
if(top==-1){cout<<"The SX_Stack is null!"<<endl;return;}
cout<<"The length of the SX_Stack is:"<<Length()<<endl;
cout<<"The content of the SX_Stack is:";
for(;top>=0;top--)
cout<<base[top];
cout<<endl;
}
};
int main()
{
SX_Stack a;
int frag=1;
while(frag)
{
while(!a.SX_StackEmpty())
{
a.ClearSX_Stack();
}
int n,s;
cout<<"Please input you want change number is:"; //输入你要转换的数
cin>>n;
cout<<"Please input you want to change into system is:"; //输入你想要转换的几进制数
cin>>s;
while(n)
{
a.Push(n%s);
n=n/s;
}
a.output();
cout<<"Do you want to continues input?yes is 1,no is 0:"; //控制是否还要输入
int i;
cin>>i;
frag=i;
}
return 0;
}*/