question about push and pop and stacks (very URGENT)

Hi,
I have a question about stacks, push, and pop, related to postfix and prefix notation. Say I have a the postfix notation of abc x+ and the reverse Polish prefix of cb x a +. Right now I have the stacks like this:

Prefix             Postfix
c                     +
b                     x
x                     c
a                     b
+                     a

Am I stacking these correctly?  With the pre-fix I'm stack LIFO (I think) and the post-fix FILO (first in last out). Sorry if this is confusing. What I basically want to know is if the stacking method is correct and if there is anything from having both stacks be LIFO or FILO.  Or put another way, how do you know how to stack a problem like this? The infix notation of this is a+ (bxc) if this helps any. I hope this makes some kind of sense. If all is lost hopefully someone can explain stacks to me and push and pop.

Thanks

Angela
collegegirlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

djwillmsCommented:
Your correct in your stacks. It was a little difficult understanding the LIFO / FIFO ordering but now that I took 45 minutes to look at it and understand it. It looks good.

To answer your question of why would you choose one method LIFO over FIFO, its all about user preference and what would make the problem the easiest to solve. When I wrote my Pascal Compiler for my Comp. Sci Bachelors degree I used 2 FILO stacks simultaneously. One stack for the variables, and one stack for the operators because it was easier to think about it, and hence code it that way. It also made tracking my variables and operators easier because my program didnt have to figure out if it was examining an operator or a variable because they were seperated in different stacks.

To describe push and pop, you must first understand that a stack is a data structure in which the last item you put in the data structure is normally the next item you would take off the stack.  The word Push means to put an item on top of the stack. The word pop means to take an item off the top of the stack.

There is nothing that would prevent you from coding any stack to be used in LILO or FILO order.  But, if you code it using LILO order the industry would probably call it a it a "queue" instead of a stack. Also, Its an industry convention that the concept of a stack is FILO ordered, just for the ease of communicating with others what your talking about..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomgalloCommented:
I agree with djwillms.
A stack is a data structure and it is commonly FIFO (first in, first out).
I do not understand your example, however if you want to do this simple calculation: a+b*c in reverse polish the stack will look like this:

FIFO:
*
c
+
b
a

A good reference for data structures is in: Data Structures in C++ by L.A. Tenenbaum -  ISBN: 0135293227
0
Arthur_WoodCommented:
there is a bit of confusion about terminlogy here.  A STACK is always LIFO - think of a stack of plates.  The last plate you put ON the stack will be the first plate you later take OFF the stack.

A QUEUE (pronounced CUE if you aren't familiar with the word), is always FIFO - a queue is like the line at your bank or super market.  When you get into the line, you wait your turn until you get to the head of the line, and then you are serviced.  A queue always services items in the exact order that they were added to the queue.  A stack always services items in the REVERSE order that they were added to the stack.

AW
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

tomgalloCommented:
Yes... Arthur is right.
My example is a LIFO...

Sorry bout that.
-tom
0
Arthur_WoodCommented:
Angela, one of the purposes of this site is to facilitate a DIALOG bewtten teh asker and the answerer(s).  That means that you should say something.  If what we told you was not clear, then you should askl for clarification.  But to NOT SAY ANYTHING, and then accept an answer, and simply grade it a B is not going to go very far in encouraging Experts here, in the future, to offer you any assistance.

Just a simple word of advice.

Glad we could assist you, in what would seem to be ab incomplete manner.

AW
0
collegegirlAuthor Commented:
Hi,
I didn't understand that  a B was a bad grade.... in college it means above average. What does it mean here? Are you supposed to give explaination if you grade below an A? Can you show me where it talks about how to grade questions on this site? I will admit that the answers wasn't clear to me so that's why I didn't give it an A but I didn't think they were bad answers. It didn't occur to me to say something back because I didn't even know where to start so I ended the question. I kind of understand how to do stacks but it still confuses me. I tried to give everyone who helped me some of the points. I didn't realize that the grade would be a problem. I always appreciate the help I get from the experts on this sites. It really helps me. That's why I wanted to give points to everyone because at least they tried to help me.

Anyway sorry for the confusion. In my world a B is pretty good but I'll keep it in mind next time.

Angela
0
tomgalloCommented:
Angela,

I agree with you.
Anyway if you are looking for some additional information, please refer to the book that I mentioned in my first post.

Hope it helps
-tom
0
collegegirlAuthor Commented:
Thanks Tom and everyone else for your help. I really do appreciate it.

Angela :)
0
Arthur_WoodCommented:
Angela, you say "I will admit that the answers wasn't clear to me so that's why I didn't give it an A but I didn't think they were bad answers.", in which case, you should ask for more explanation.  We are trying to make it as clear as possible, so that you can learn from the experts here.  And a while a B is a 'good' grade, if you don't ask for more expalantion when something is not clear, how are we to be able to guess that you need more in the way of information.  When you don't ask we must assume that what has been provided satisfies your current needs, and no further effort is needed.  In that casxe, a 'B' seems to be a 'slap in trhe face'.  Most of the people here have many claims on their time, and cannot/will not volunteer more details that seems to be needed, just to see their words types on the screen.  If more details are needed, and that need is expressed, then we are more than willing to explain, but when the need is not expressed, then very few will offer what would appear to be un-needed verbage.

AW
0
tomgalloCommented:
Let it go Arthur... let's move on.

-tom
0
collegegirlAuthor Commented:
Hi again,
I'm sorry but I am confused. I didn't mean to slap anyone in the face and I'm not sure how I did. I really do appreciate the help everyone gives me....its been crucial for me this semester. I really didn't think a B would offend anyone. I have read the help section about grading and I will take it into consideration next time I ask a question and grade someone, as I know that its important to the experts. I'm new to this site and I tried to explain why I gave the grade I did but it still seems to be misunderstood. I don't know anything else to say except I'm learning as I go along so please be patient with me.

Thanks again Tom and everyone else who helped,

Angela
0
tomgalloCommented:
No problem Angela, your decision was correct to my eyes... it is what I had done in your position.
You not have to explain your actions here to anyone. Who cares A, B or C anyway... the purpose here is "help each other" not "compete each other, be the first and the hell with others" so... again, you not have to explain anything!!!

Enjoy the information!!! Enjoy the site!!! Keep going...
-tom
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.