#include<iostream>
const int MaxStackSize 10;
class Stack
{
DataType StackList[MaxStackSize];
int top;
public:
stack();
bool IsEmpty();
bool IsFull();
DataType GetTop();
void Push(DataType x);
DataType Pop();
void Clear();
};
Stack::stack()
{
top=-1;
}
bool Stack::IsEmpty()
{
if(top==-1)
return true;
else
return false;
}
bool Stack::IsFull()
{
if(top==MaxStackSize-1)
return true;
else
return false;
}
DataType Stack::GetTop()
{
if(IsEmpty())
{
cout<<"栈空!"<<endl;
exit(0);
}
return StackList[top];
}
void Stack::Pop()
{
if(IsEmpty())
{
cout<<"栈空!"<<endl;
exit(0);
}
return StackList[top--];
}
void Stack::Clear()
{
top=-1;
};
int main()
{
Stack s;
int a[10];
int i;
cout<<"请输入10个数:";
for(i=0;i<10;i++)
{
cin>>a[i];
s.Push(a[i]);
}
for(i=0;i<10;i++)
{
s.Top(a[i]);
cout<<a[i]<<" ";
s.Pop();
}
return 0;
}
你贴上来的程序根本编译不过啊,针对性的修改了下,修改部分在如下的代码中用注释标示了出来,请注意跟你的程序对比下~~:
#include<iostream>