编程高手帮帮忙!栈的基本操作学的
我用VC6。 0写的,你看看有没有什么问题
#include
using namespace std;
templateclass MyStack
{
private:
T *theStack; //内部堆栈
T *top; //栈顶指针
T *bottom; //栈底指针
T *full; //栈满指针
public:
//初始化
MyStack(int max)
{
//theStack=(T *)malloc(sizeof(T)*(max+1));
theStack=new T[max+1];
memset(theStack,0,sizeof(T)*(...全部
我用VC6。
0写的,你看看有没有什么问题
#include
using namespace std;
templateclass MyStack
{
private:
T *theStack; //内部堆栈
T *top; //栈顶指针
T *bottom; //栈底指针
T *full; //栈满指针
public:
//初始化
MyStack(int max)
{
//theStack=(T *)malloc(sizeof(T)*(max+1));
theStack=new T[max+1];
memset(theStack,0,sizeof(T)*(max+1));
top=bottom=theStack;
full=theStack+max*sizeof(T);
}
//入栈
void push(T theNum)
{
if(theStack==NULL || full=top)
return 0;
T *temp=NULL;
temp=top;
top=top-sizeof(T);
return *temp;
}
//判空
bool isempty()
{
if(theStack==NULL || bottom>=top)
return true;
return false;
}
//析构函数
~MyStack()
{
top=bottom=full=NULL;
delete theStack;
}
};
//数字转字符函数
char numtochr(int input)
{
if(input>-1 && input *a=new MyStack(50);
int input=0;
int mode=0;
cout>input;
cout>mode;
if(mode>16 || modepush (numtochr(input%mode));
input=input/mode;
if(!input)
break;
}
while(!a->isempty() )
coutpop ();
cout<收起