I'm writing an infix to postfix program. All has been slowly but surely going well, but now I'm actually running the program after getting rid of all warning and errors the compiler found, and there's a problem with a loop somewhere that I can't figure out.
I'm pretty sure the problem lies in my queue class, as what I'm getting is endless lines of "Queue is full". But I can't spot what's wrong, although it's probably something simple.
There could also be a problem in this function, but I think it's ok.Code:Queue::Queue() { Front = Rear = 0; }//end constructor bool Queue::Empty() { return Front == Rear == 0; }//end Empty void Queue::Enqueue(int element) { if(Rear+1 == Front || (Rear+1 == maxqueue && !Front)) { cout << "Queue is full\n"; return; }//if Rear++; if(Rear == maxqueue) Rear = 0; //circle Cue[Rear] = element; }//end Enqueue int Queue::Dequeue() { if (Front == Rear) { cout << "Queue is empty\n"; return 0; }//if Front++; if (Front == maxqueue) Front = 0; return Cue[Front]; }//end Dequeue
Code:void infix_to_postfix(string infix) { Stack stak; Queue cue; for (int i=0; i<infix.size(); i++){ if (infix[i] == '+' || infix[i] == '-' || infix[i] == '*' || infix[i] == '/' || infix[i] == '^' ){ while (!stak.Empty() && order_ops(stak.Top()) <= order_ops(infix[i])){ cue.Enqueue(stak.Top()); stak.Pop(); }//while stak.Push(infix[i]); }//if else if(infix[i] == '('){ stak.Push(infix[i]); }//else if else if(infix[i] == ')'){ while (stak.Top() != '('){ cue.Enqueue(stak.Top()); stak.Pop(); }//while stak.Pop(); }//else if else{ cue.Enqueue(infix[i]); }//else } //for while (!stak.Empty()){ cue.Enqueue(stak.Top()); stak.Pop(); } // Print queue (postfix) to screen if (!cue.Empty()) cout << "Postfix : " << endl; while(!cue.Empty()){ cout << cue.Dequeue(); //cue.Dequeue(); }//while cout << endl << endl; }//end infix_to_postfix



LinkBack URL
About LinkBacks


