基本分析可以看另一篇文章C++实现四则运算器(无括号)
栈的实现
//stack.h
#ifndef STACK_H
#define STACK_H
#include<iostream>
class stack_int
{
private:
int* bottom; //栈底
int* top; //栈顶
unsigned int capacity;//栈容量
unsigned int size; //栈大小
public:
stack_int() :bottom(new int[11]), top(bottom), capacity(10), size(0) {
};
stack_int(unsigned int capacity) :bottom(new int[capacity+1]),top(bottom), capacity(capacity),size(0){
};
int operator[](unsigned int i) const
{
return *(bottom + i);
}
bool isEmpty()const {
return bottom == top; }
bool isFull()const {
return size == capacity-1; }
unsigned int getsize()const {
return size; }
unsigned int getcapacity()const {
return capacity; }
int gettop()const
{
if (!isEmpty())
return *(top - 1);
else
return -1;
}
void settop(int i)
{
if (!isEmpty())
{
*(top -