简体   繁体   English

表达式:双端队列迭代器不可取消

[英]Expression:Deque iterator not dereferencable

I am writing program in C++ to convert infix to postfix. 我正在用C ++编写程序,将中缀转换为后缀。 Here is my code. 这是我的代码。

#include<iostream>
#include<stack>
#include<string.h>

using namespace std;


int getPrecedence( char tmp )
{
    if(tmp=='+')
    {
        return 1;
    }
    else if(tmp == '-')
    {
        return 1;
    }
    else if(tmp == '*')
    {
        return 2;
    }
    else if(tmp == '/')
    {
        return 2;
    }
}

int main()
{

    stack<char> st;

    char expression[10];


    //cout<<"Enter expression : ";
    //cin>>expression;

    strcpy(expression,"a+b*c/d-e");

    char postfix[100];  // its postfix string
    int counter=0;

    int i=0;


    while( expression[i] != '\0' )  // iterate till '/0' does not come.
    {
        if(expression[i]== '+' || expression[i]== '-' || expression[i]== '*' || expression[i]== '/'  )
        {
            if( st.empty() )
            {
                st.push(expression[i]);
            }
            else // when stack not empty
            {
                int topPrecedence = getPrecedence( st.top() );
                int expressionPrecedence = getPrecedence( expression[i] );


                while( !(topPrecedence < expressionPrecedence) )
                {
                    postfix[counter++] = st.top();
                    st.pop();
                    topPrecedence = getPrecedence( st.top() );
                }

                if( st.empty() )
                {
                    st.push( expression[i] );
                }

                if( topPrecedence < expressionPrecedence )
                {
                    st.push( expression[i] );
                }


            }
        }
        else // when its an alphabet 
        {
            postfix[counter++] = expression[i];
        }


        i++;
    } // outer while ends 

    while( ! st.empty() )
    {
        postfix[counter++] = st.top();
        st.pop();
    }


    postfix[counter] = '\0';
    i=0;

    while( postfix[i] != '\0' )
    {
        cout<<postfix[i]<<" ";
        i++;
    }



    system("pause");
    return 0;
}

For example if input expression is a+b*c/de . 例如,如果输入表达式是a+b*c/de Till d it converts expression postfix. 直到d它转换表达式后缀。 But when - comes. 但是,当-来。 It shows following error. 它显示以下错误。

Expression:deque iterator not dereferencable

Apparently its related to Queue and I have not even used Queue. 显然,它与Queue有关,我什至没有使用Queue。

Screen capture: https://www.facebook.com/photo.php?fbid=241461649373492&set=a.118955391624119.1073741827.100005289761090&type=1 Screen capture: https Screen capture: //www.facebook.com/photo.php?fbid=241461649373492&set=a.118955391624119.1073741827.100005289761090&type=1

The stack is a container adaptor. 堆栈是一个容器适配器。

By default it adapts a deque . 默认情况下,它采用deque You're probably just popping from an empty stack. 您可能只是从空堆栈中弹出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “双端队列迭代器不可引用”错误 - “Deque iterator not dereferencable” Error C ++:deque迭代器不可取消 - C++ :deque iterator not dereferencable 表达式:不可迭代的字符串迭代器 - Expression: String iterator not dereferencable C ++为什么“ deque迭代器不可取消” - C++ why “deque iterator not dereferencable ” 执行std :: deque-&gt; front()时&#39;deque iterator not dereferencable` - 'deque iterator not dereferencable` while doing std::deque->front() 如何在std :: deque中避免`deque iterator not dereferencable`? 锁? - How to avoid `deque iterator not dereferencable` in a std::deque ? Locks? 在调试模式下抛出 C++“deque iterator not dereferencable”异常 - C++ "deque iterator not dereferencable" exception is thrown in debug mode 当队列不为空时,queue.front()上的“ deque迭代器不可解除” - “deque iterator not dereferencable” at queue.front() when queue is not empty C ++“不可取消deque迭代器”多线程。 WaitForSingleObject()使线程通过 - C++ “deque iterator not dereferencable” multithreading. WaitForSingleObject() lets the thread through 避免非托管C ++,C ++ / CLI和C#代码之间的std :: deque迭代器不可解除错误 - Avoiding std::deque iterator not dereferencable error between unmanaged c++, c++/cli and c# code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM