Dequeue iterator not found

Discussion in 'C++' started by imueed, Nov 13, 2015.

  1. imueed

    imueed New Member

    Joined:
    Nov 13, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I'm making a program that turns infix to postfix.
    Please identify the error
    Code:
    #include <iostream>
    #include <string>
    #include <stack>
    using namespace std;
    
    double solve_expression(string infix);
    string convert_to_postfix(string infix);
    double evaluate_postfix(string postfix);
    
    void main()
    {
    	do{
    		cout<<"Press 1 to convert infix to postfix"<<endl;
    		cout<<"Press 2 to evaluate postfix expression"<<endl;
    		cout<<"Press E/e to EXIT"<<endl;
    		char option='0';
    		cin>>option;
    		system("CLS");
    
    		switch(option)
    		{
    		case '1':
    			{
    				cout<<"Question 1"<<endl;
    			
    				stack <char> output;
    				string infix="(1+2–3)*4–(5+6)";
    				string postfix;
    
    				postfix= convert_to_postfix(infix);
    				cout<<postfix;
    				
    				
    
    
    				break;
    			}
    
    		case '2':
    			{
    				cout<<"Question 2"<<endl;
    				break;
    			}
    
    		case 'E':
    		case 'e':
    			{
    				exit (-1);
    			}
    
    		default:
    			{
    				cout<<"Invalid input"<<endl;
    			}
    
    
    	}
    
    }
    		while (-1);
    }
    
    string convert_to_postfix(string infix)
    {
    	string output="";
    	stack <char> op;
    	for(int i=0;i<infix.length();i++)
    	{
    		if(infix[i]=='0'||infix[i]=='1'||infix[i]=='2'||infix[i]=='3'||infix[i]=='4'||infix[i]=='5'||infix[i]=='6'||infix[i]=='7'||infix[i]=='8'||infix[i]=='9')
    		{
    			char c=infix[i];
    			output+=c;
    		}
    
    		if(infix[i]=='(')
    		{
    			op.push(infix[i]);
    		}
    
    		if(infix[i]=='/'||infix[i]=='*'||infix[i]=='+'||infix[i]=='-')
    		{
    			while(op.top()>infix[i]||op.top()==infix[i])
    			{
    				char c=op.top();
    				op.pop();
    				output+=c;
    			}
    
    			op.push(infix[i]);
    		}
    
    		if(infix[i]==')')
    		{
    			while(infix[i]!='(')
    			{
    				char c=op.top();
    				op.pop();
    				output+=c;
    			}
    		}
    
    				
    		
    }
    	while(!op.empty())
    		{
    				char c=op.top();
    				op.pop();
    				output+=c;
    		}
    
    	return output;
    }
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    There's an error on line 10.

    Does it compile OK? If not, what errors do you get?
    What output do you get when you run the program?

    Try adding some debug statements; that should help you find the error. If the problem is that you get a crash, make sure you use fflush(stdout); so that the screen output accurately reflects the latest message printed by the code.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice