   prefix/postfix evaluation in C / C++?
  Hi, anyone know how to evaluate prefix (or postfix)expressions?I finally found a tutorial which teach people how to convert infix->prefix, infix->postfix... in a string.But then now I need to evaluate them... how? I need one which can evaluate long expresion... (or atleast not just 2 var and 1 op... i kinda fig out how to evaluate 2 var, but i need to evaluate more than 2 var and 1 op...)Thanks for helping~  ( sorry for being rude, but i need the tutorial badly...  )[edited by - NewbieA on February 6, 2004 10:03:20 AM]
  i am not sure what you are asking....but are you asking for trying to figure out something like2 + 3 + 4let the user type something in like that and then the computer returns the answer ?it is really just an extension of just adding two numbers together which you said you have figure out alreadyparse all that out into a buffer likeint main()char buf[10][8];   // just some numbers for the size// i know you cant do this but this is pseudo codebuf[0] = "2";buf[1] = "+";buf[2] = "3";buf[3] = "+";buf[4] = "4";buf[5] = NULL;int left = atoi(buf[0]);if (buf[1] == "+")  answer = addNumbers(left, 2);cout << answer;}//////////////////////////////////////////////////int addNumbers(int left_value, int next_buf_index){ int right_value = atoi(buff[next_buff_index]);    next_buff_index++; int ans = left_value + right_value;  // at end of user entered input if (buff[next_buff_index] == NULL)    return ans;  return addNumbers(ans, next_buff_index);}  it is recursion basically...hope you know what that isyou of course need to add some if statements to detect if it is other operations besides just adding   "A soldier is a part of the 1% of the population that keeps the other 99% free"  - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA ;  Yes, that's what i meant, ncsu121978.(Sorry if i start to talk strangly, coz i've been trying to fig out how to do this the whole day... )user input : 2 + 3 + 4and prefix is : + + 2 3 4  ..,right?i reach this far... ( + + 2 3 4, in char[] ), but then...@_@ is what i couldn't fig out...Thanks ncsu121978,Thanks  [edited by - NewbieA on February 6, 2004 10:22:00 AM];  well then once you get those prefixes parsed into your buffer like you have themthen rearrange them to fall between the numbers in the buffer and then use my methodor you could use some kind of queue and place the operators in the queue.   now you know to use the first operator in the queue on the first two numbersthe next operator in the queue on that answer and the third numberthe next operator in the queue on that answer and the fourth number....wash, rinse, repeat   and what does @_@ mean ?"A soldier is a part of the 1% of the population that keeps the other 99% free"  - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA   [edited by - ncsu121978 on February 6, 2004 10:29:38 AM];  @_@   <- getting dizzyjust like : )  mean smile... or is there already one mean dizzy?