A simple stack
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A simple stack相关的知识,希望对你有一定的参考价值。
// 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;
}
以上是关于A simple stack的主要内容,如果未能解决你的问题,请参考以下文章