6.3w+
社区成员
static const int INIT_SIZE = 100; //の..我的可以通过啊~
base=top=(T *)new(nCapacity*sizeof(T));
base=top=new T[nCapacity];
#include<stack>//这是C++里本来就有的吗?老师要我们写栈的一个类啊~这是我怕麻烦,就只写了几个函数...能不能看看
base=top=(T *)new(nCapacity*sizeof(T)); //是哪里错了啊??//关于整形数的进制计算
#include<iostream>
#include<stack>
using namespace std;
void main()
{
stack<char>s;
int n,a,m;
cout<<"输入一个数";
cin>>n;
cout<<"输入进制";
cin>>m;
cout<<n<<"=";
if(m<n)
{
while(n)
{
a=n%m;
n/=m;
if(a>9)
a=65+a-10-48;// 凑成英文字母的ASC值
s.push(a+48);//加上48后变成ASC的数字
}
}
else
{
while(n)
{
a=n%m;
n/=m;
if(a>9)
a=65+a-10-48;// 凑成英文字母的ASC值
s.push(a+48);//加上48后变成ASC的数字
}
s.push(48);//多输入一个0即可
}
while(!s.empty())
{cout<<s.top();
s.pop();
}
cout<<endl;
}
base=top=(T *)new(nCapacity*sizeof(T)); //是c还是c++??
static const int INIT_SIZE = 100; //我的编译器是通不过的?不晓得你的可以不?
static const int INCREMENT = 10;
#include <iostream>
using namespace std;
enum Status
{
stOk = 1,
stError = 0,
};
template <class T> class Zhan
{
public:
Zhan(int nCapacity = INIT_SIZE);
~Zhan();
bool Isempty(){return top!=base;}
Status Push(T e);
Status Pop(T &e);
protected:
T* base;
T* top;
int stacksize;
enum{ INIT_SIZE = 100, INCREMENT = 10};
};
template <class T>
Zhan <T>::Zhan(int nCapacity=INIT_SIZE)
{
base=top=new T[nCapacity];
try
{
if(!base)
throw stError;
}
catch(...)
{
cerr <<"error" <<endl;
exit(1);
}
}
template <class T> Zhan <T>::~Zhan(void)
{
while(base!=top)
{
delete top;
top=top-sizeof(T);
}
}
template <class T> Status Zhan <T>::Push(T e)
{
*top++=e;
return stOk;
}
template <class T> Status Zhan <T>::Pop(T &e)
{
try
{
if(base==top)
throw stError;
}
catch(...)
{
cerr <<"error" <<endl;
exit(1);
}
e=*--top;
return stOk;
}
void main()
{
int a,e;
Zhan <int>z;
cout <<"数制转换:请输入一个十进制数:" <<endl;
cin>>a;
while(a)
{
z.Push(a%8);
a=a/8;
}
while(z.Isempty())
{
z.Pop(e);
cout <<e;
}
}