Its 0332hrs!!! AAAAAAAAARGHGGG!!!! WHO’S YOUR DADD…
Its 0332hrs!!! AAAAAAAAARGHGGG!!!! WHO’S YOUR DADDY!!!!!!
///////////////////////////////////////////////////
/////
///// LogName: u0508802
///// FullName:
///// CreationDate: 2006-09-20 00:13:28
/////
///////////////////////////////////////////////////#include
#include
#include
#includeusing namespace std;
int eval(string&, string&);
void convert(list& );//—————————
//Main function
int main()
{
list v;
list::iterator i = v.begin();
stack numstack;convert(v);
//print output
while (i != v.end())
cout & v){
stack ops;
list::iterator i = v.begin();
string line, item;
int counter=0;//read whole line
getline(cin, line);//create string stream
istringstream istrs(line);//read from line into item string until next space is met
while(!istrs.eof()) {
istrs >> item;//decide what to do with operators
//if its an operator add to stack unless its ) then pop until (
if (item == “(”){
ops.push(”(”);
}if (item == “)”){
while (ops.top() != “(”){
v.insert(i, ops.top());
ops.pop();
}
ops.pop();
}if (item == “*”){
ops.push(”*”);
}if (item == “/”){
ops.push(”/”);
}if (item == “+”){
ops.push(”+”);
}if (item == “-”){
ops.push(”-”);
}//decide what to do with numbers
if (item != “-”)
if (item != “+”)
if (item != “*”)
if (item != “/”)
if (item != “(”)
if (item != “)”){
//put number into list
v.insert(i, item);
}}//End of While
// flush ops stack and print content
cout &) {
int answer;
string line, item;
//read whole line
getline(cin, line);//create string stream
istringstream istrs(line);//read from line into item string until next space is met
while(!istrs.eof()) {
istrs >> item;
}
return answer;
}
That took me 4 hours! ARGH!!!!!!!!!!! you can’t imagin how i’m feeling now!!! RAHHHHHHHHHHHHHHHHHHHHHHH!!!! hahaha… I’m halfway there! I hope i’ll be done before i go to school.
it converts infix expressions to postfix to calculate.
so ( 1 + 2 ) / ( 3 * 4 ) becomes 1 2 + 3 4 * /
basically this is to eliminate use of parenthesis and have no ambiguity in evaluating an expression. check here for a mini lecture on how to evaluate a postfix expression and just watch the animation to get an idea.