Thread: stack project

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Ok, you seem to be slowly cathing the concept. The one problem that you have with the code up here is that you're placing (and for the record, "pushing" something in a stack is not placing it on top...) the result back on top of the stack. You don't want to do this. After the initial operation, you then want to pop the remaining element of the stack one at a time and execute the corresponding operation with the result of the previous operation. You then repeat this process until the stack is empty. Then you can output the result.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    52
    ok, sorry I'm having so much trouble with this. I don't understand what you trying to tell me. are you saying that I'm never popping the value of the expression? I don't get it. thanks for trying to help also.

  3. #3
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Here's an example :

    235 +*

    First you pile up everything in two stacks :
    Value Stack Op Stack
    5 *
    3 +
    2

    Then you pop an element from each stack :
    Value Stack Op Stack
    3 +
    2

    And pop another element from the value stack and execute the desired operation (3*5) :
    Value Stack Op Stack
    2 +

    Cumulative result : 15

    Again, pop an element from each stack and execute the desired operation to the cumulative result (15 + 2):
    Both Stacks Empty

    Cumulative Result : 17

    Now both stacks are empty, so you know you're done. Output the cumulative result.

    Hope that helps
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. Need Help with Stack
    By trongsi in forum C++ Programming
    Replies: 9
    Last Post: 05-23-2006, 04:14 PM
  3. Finished Stack
    By the pooper in forum C Programming
    Replies: 11
    Last Post: 02-02-2005, 10:52 AM
  4. Stacks
    By Cmuppet in forum C Programming
    Replies: 19
    Last Post: 10-13-2004, 02:32 PM
  5. What am I doing wrong, stack?
    By TeenyTig in forum C Programming
    Replies: 2
    Last Post: 05-27-2002, 02:12 PM