This is the main part of a project
I assume all other header and cpp file are correct
cuz most of them are copy from books n the professor
when I run it, "right after the input"
the program sort of stopped, pop out a error message, then keep running
n crashed after my test part of printing out the "queue"
so I assume there got to be a error for input?!
n maybe when translating from prefix to postfix?
please anyone, help me out by simply point out my error(or maybe it isn't that simple)
I wish to learn from my own error, n help out someone else someday

// LAB2.cpp
#include "Utility.h"
#include "Stack.h"
#include "Queue.h"
#include <iostream>
#include <string>
using namespace std;

void input(Queue prefixQ);
void pre_to_post(Queue prefixQ, Queue postfixQ);
void output(Queue postfixQ);
bool is_operator(char ch);

int main()
{ Queue prefixQ, postfixQ;
  char answer;
  do
  { input(prefixQ);
    pre_to_post(prefixQ, postfixQ);
    output(postfixQ);
    cout<<endl<<"continue? N for NO: ";
    cin>>answer;
  } while(!(answer=='n'||answer=='N'));

  return 0;
}

void input(Queue prefixQ)
{ string pref;
  int i=0;
  cin>>pref;
  while(pref[i])
  { prefixQ.append(pref[i]);
    i++;
  }
}
void pre_to_post(Queue prefixQ, Queue postfixQ)
{ Stack_entry se1;
  Stack S;
  char ch;
  while(!prefixQ.empty())
  { prefixQ.retrieve(ch);
    prefixQ.serve();
    if(is_operator(ch))
    { se1.element=ch;
      se1.flag=false;
      S.push(se1);
    }
    else
    { postfixQ.append(ch);
      S.top(se1);
      while(se1.flag!=false)
      { if(se1.flag==false)
        { se1.flag=true;
          S.push(se1);
        }
        else
        { S.pop();
          postfixQ.append(se1.element);
        }
        S.top(se1);
      }
      se1.flag=true;
      S.push(se1);
    }
  }
}
void output(Queue postfixQ)
{ char ch;
  while(!postfixQ.empty())
  { postfixQ.retrieve(ch);
    postfixQ.serve();
    cout<<ch;
  }
  cout<<endl;
}

bool is_operator(char ch)
{ if(ch=='+'||ch=='-'||ch=='*'||ch=='/')
    return true;
  else
    return false;
}

This is the main part of a project
I assume all other header and cpp file are correct
cuz most of them are copy from books n the professor

Bad assumption. Check them to make sure they are correct.
And n is not a word. Be sure to reread the member rules, especially about being clear.

when I run it, "right after the input"
the program sort of stopped,

Sort of stopped? Are we supposed to understand what that means?

pop out a error message,

The error it "popped out" wasn't important enough to tell us, should we guess?

then keep running
n crashed after my test part of printing out the "queue"

Stopped, error, kept running, then crashed? Weird...

so I assume there got to be a error for input?!
n maybe when translating from prefix to postfix?

Could be anything. Try pinpointing exactly where the crash happens.

please anyone, help me out by simply point out my error(or maybe it isn't that simple)
I wish to learn from my own error, n help out someone else someday

Try explaining in detail what is happening. We sort of can't tell with sort of explanations.

Add output statements to see if the correct stuff is happening at the correct times, like the input was read correctly.

Sorry about the "n" word
I'll make sure I use the proper word next time when post

I can try to describe what happened when I run the program
the program first ask the user to enter a string of prefix equation

right after I enter my input and hit the enter key, a message box pops out
the embarrassing part is i can not remember what it says
I do not have the visual c++ 2010 install on this computer
I'll post it once I get back to my own computer

what happens next is a message asking me if I want to continue running the program

when I put a line outputing what is in the queue right after copy the string into queue, the output came out correctly

then it crashed

these are the steps that happens every time I run the program
I'm assuming the crash happens at the pre_to_post function because I put the output command at the end of input function, and it did output the queue.
input function should be cleared, although there must be some minor errors in it causing the error message?
output function works fine as well, so that leaves pre_to_post alone.

I'll check back with my friend if my pre_to_post has a logic error in it
but maybe someone can figure out what is wrong with the input that causing the error message??
like I said, I'll update the error message once I get back to my own computer

please help me out, if there is any other confusion please let me know

This article has been dead for over six months. Start a new discussion instead.