数据结构(C++版)栈与队的的应用(括号匹配问题),要求在下面的问题补充.用类定义的.

1个回答

  • #include

    using namespace std;

    class Stack

    {

    public:

    int size;

    int top;

    char *stack;

    Stack(int m);

    bool push(char item);//入栈

    bool pop();//出栈

    bool isempty();//是否为空

    void clear();//清空栈

    int Size();//栈中元素个数

    ~Stack();

    char Top();

    };

    #include

    using namespace std;

    Stack::Stack(int m){

    top=-1;

    stack=new char[m];

    size = 0;

    }

    void Stack::clear(){

    delete []stack;

    size = 0;

    stack=NULL;

    }

    Stack::~Stack(){

    clear();

    }

    bool Stack ::push(char item){

    top++;

    stack[top]=item;

    size++;

    return true;

    }

    bool Stack::isempty(){

    if(stack == NULL)

    return true;

    else

    return false;

    }

    bool Stack::pop(){

    if(isempty()){

    cout