【问题标题】:My st.show on stack cannot be display for some reason由于某种原因,我的堆栈上的 st.show 无法显示
【发布时间】:2022-11-12 16:52:51
【问题描述】:

我的代码的问题是当我运行它时,它说错误没有匹配的函数调用 stack::show() 我有。我不知道我的代码有什么问题。

如果我在选择中输入 2,它将显示我的堆栈,而我的第三个选择仍在解决。

【问题讨论】:

标签: c++ visual-c++


【解决方案1】:
private:
    int MAX;
    int top;
    string *arr_q;

public:
    Stack (int size)
    {
        MAX=size;
        top=-1;
        arr_q=new string[MAX];
    }
    void push(string subs)
    {
    if ((top+1)==MAX)
        cout << "Stack Overflow..." << endl;
    top=top+1;
    arr_q[top]=subs;
    }

    void show(int lim)
    {
    int i = lim;
    cout<<"Stack contains --"<<endl;
    for (int ctr=i; ctr>=0; ctr--)
    {
        if (ctr==i)
            cout<<"		"<<arr_q[ctr]<<"<--Top of Stack"<<endl;
        else
            cout<<"		"<<arr_q[ctr]<<endl;
    }
    }
};

case 2: {
st.show();
break;

【讨论】:

  • 这应该是你问题的一部分,请拿走tour并阅读How to Ask。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多