-
Oct 23rd, 2005, 02:54 PM
#1
Thread Starter
Junior Member
Stack questions
hi, i was going throught java exercise i did not get this exercise? if you know anything please post your comments here.
Which of the following applications may use a stack?
A. A parentheses balancing program.
B. Keeping track of local variables at run time.
C. Syntax analyzer for a compiler.
D. All of the above.
-
Oct 24th, 2005, 09:31 PM
#2
-
Nov 12th, 2005, 05:52 PM
#3
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 12th, 2005, 08:30 PM
#4
New Member
Re: Stack questions
Originally Posted by indianj
hi, i was going throught java exercise i did not get this exercise? if you know anything please post your comments here.
Which of the following applications may use a stack?
A. A parentheses balancing program.
B. Keeping track of local variables at run time.
C. Syntax analyzer for a compiler.
D. All of the above.
The question is, do you know what a stck is? If not, then we can explain - then you will be able to answer the question all by yourself
I am the real Santa Clause
-
Nov 13th, 2005, 02:50 PM
#5
Thread Starter
Junior Member
Re: Stack questions
thanks for your answer. yes i do not stack now.
-
Nov 13th, 2005, 03:19 PM
#6
New Member
Re: Stack questions
You have a large number of presents and you put them together, you put one present on top of the other. This is a stack. If you try to take one of the presents form the middle of the stack, all the others will fall. So you can only take something off the top of the stack.
A stack is referred to as a LIFO (Last in First Out) - and they are used often in programming. For example, in a program you have a calling stack, each time you call a function, a pointer is pushed (placed) on the calling stack, once the current function has finished executing, the last item on the called stack is popped (taken off) and execution resumes form the next statement in the calling function. Once the stack is empty and the current execution has finished the program ends.
Another implementation of stacks is Reverse Polish notation, whereby a mathematical expression is represented by string. All numbers are pushed on to the stack and operators cause two numbers to be popped from the stack and a portion of the expression to be solved. Calculators and computers use these.
So, to work out where a stack might be used think of situation where you need to store a set of data but only ever require/want the last item you put inside the store. If we use Java as an example and apply it to this statement:
B. Keeping track of local variables at run time.
In Java locals variables mask variables of the same name which are member of the current class. Each block in which a variable is declared masks the higher scope. So it would be sensible to assume that like the calling stack, a variable stack exists too.
I am the real Santa Clause
-
Nov 13th, 2005, 04:00 PM
#7
Re: Stack questions
just say B for god's sake
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 13th, 2005, 04:13 PM
#8
Re: Stack questions
I would use stacks in C too. especially when you are analyzing syntax which is likely to be nested. I.e: nested loops and if statements.
Last edited by visualAd; Nov 13th, 2005 at 04:28 PM.
-
Nov 16th, 2005, 12:17 AM
#9
Re: Stack questions
I still keep with D since I have tried all the first 3 choices and implemented them all using a stack. heck its even in the compiler book to use a stack. :s
-
Nov 16th, 2005, 12:19 AM
#10
Re: Stack questions
I still agree with you ocean
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 16th, 2005, 12:20 AM
#11
Re: Stack questions
A. was in the Data structure book.
B. was an example in system architecture book.
C. was in the compiler book.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 16th, 2005, 12:21 AM
#12
Re: Stack questions
Originally Posted by ComputerJy
I still agree with you ocean
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|