// simple stack.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;
const int SIZE = 100;
class Stack
{
public:
void init()
{
position = 0;
}
char push(char ch);
char pop();
private:
char stk[SIZE];
int position;
};
char Stack::push(char ch)
{
if (position == SIZE)
{
cout << endl << "stack is full" << endl;
return 0;
}
stk[position++] = ch;
return ch;
}
char Stack::pop()
{
if (position ==0)
{
cout << endl << "stack is null" << endl;
return 0;
}
return stk[--position] ;
}
int main()
{
Stack s;
s.init();
char ch;
cin >> ch;
while (ch != '!'&&s.push(ch))
cin >> ch;
cout << "data in stack:";
while (ch = s.pop())
cout << ch;
system("pause");
return 0;
}