65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class A
{
int top;
int buffer[100];
public:
A() {top=-1;}
bool push(int i)
{
if(top==100-1)
{
cout <<"stack is overflow.\n";
return false;
}
else
{
top++;
buffer[top]=i;
return true;
}
}
public:
void disp()
{
int i;
for(i=0;i <=this->top;i++)
cout << this->buffer[i];//
}
};//
int main()
{
int x;
A st;
cin >> x;
st.push(x);
st.disp();
return 0;//
}
#include <iostream>
using namespace std;
class A
{
int top;
int buffer[100];
public:
A() {top=-1;}
bool push(int i)
{
if(top==100-1)
{
cout <<"stack is overflow.\n";
return false;
}
else
{
top++;
buffer[top]=i;
return true;
}
}
public:
void disp(int bufferd[])
{
int i;
for(i=0;i <=top;i++)
cout << bufferd[i];
}
}; //此处未加;
int main()
{
int x;
A st;
cin >> x;
st.push(x);
st.disp(st.buffer); //buffer被定义成私有成员函数,所以在此处不能调用
return 1;
} #include <iostream>
using namespace std;
class A
{
int top;
int buffer[100];
public:
A() {top=-1;}
bool push(int i)
{
if(top==100-1)
{
cout <<"stack is overflow.\n";
return false;
}
else
{
top++;
buffer[top]=i;
return true;
}
}
public:
void disp()
{
int i;
for(i=0;i <=top;i++)
cout << buffer[i];
}
};
int main()
{
int x;
A st;
cin >> x;
st.push(x);
st.disp();
return 1;
}