application of stacks.

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Thread Solved

Join Date: Jan 2009
Posts: 42
Reputation: scias23 is an unknown quantity at this point 
Solved Threads: 0
scias23's Avatar
scias23 scias23 is offline Offline
Light Poster

application of stacks.

 
-1
  #1
Mar 1st, 2009
i have this question..

show the state of the stack and the value of each variable after execution of the following statements.

let A=5, B=3, C=7

push A onto stack
push C*C onto stack
pop item fron the stack and store in B
push B+A onto stack
pop item from the stack and store in A
pop item for the stacj and sotore in B

-------------------------------------
what will be the value of B after C*C is popped out of the stack?? will the predefined value of B be overwritten?? and what if B is pushed onto the stack, will the value of the pushed B be the value of the result of C*C??

for example..

this???
push A onto stack = 5
push C*C onto stack = 49
pop item fron the stack and store in B = B=49
push B+A onto stack = 49+5=54
pop item from the stack and store in A = A=54
pop item for the stacj and sotore in B = B=5
??????????????????????

or this??
push A onto stack = 5
push C*C onto stack = 7*7=49
pop item fron the stack and store in B = B=49
push B+A onto stack = 3+5=8
pop item from the stack and store in A = A=8
pop item for the stacj and sotore in B = B=5
???????????????????/

HELP
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,044
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: application of stacks.

 
1
  #2
Mar 1st, 2009
When you store something in B, that means the predefined value will be overwritten.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3
Reputation: GPMan is an unknown quantity at this point 
Solved Threads: 1
GPMan GPMan is offline Offline
Newbie Poster

Re: application of stacks.

 
0
  #3
Mar 1st, 2009
They want you to show the state of the stack, ie what's in it.

So more like

push A onto stack [5]
push C*C onto stack [49,5]
...
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,044
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: application of stacks.

 
1
  #4
Mar 1st, 2009
Anyway, your first example (where A gets assigned 54) is perfectly right.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 4
Reputation: ajeet choudhary is an unknown quantity at this point 
Solved Threads: 0
ajeet choudhary ajeet choudhary is offline Offline
Newbie Poster

Re: application of stacks.

 
0
  #5
Sep 30th, 2009
Originally Posted by scias23 View Post
i have this question..

show the state of the stack and the value of each variable after execution of the following statements.

let A=5, B=3, C=7

push A onto stack
push C*C onto stack
pop item fron the stack and store in B
push B+A onto stack
pop item from the stack and store in A
pop item for the stacj and sotore in B

-------------------------------------
what will be the value of B after C*C is popped out of the stack?? will the predefined value of B be overwritten?? and what if B is pushed onto the stack, will the value of the pushed B be the value of the result of C*C??

for example..

this???
push A onto stack = 5
push C*C onto stack = 49
pop item fron the stack and store in B = B=49
push B+A onto stack = 49+5=54
pop item from the stack and store in A = A=54
pop item for the stack and store in B = B=5
??????????????????????

or this??
push A onto stack = 5
push C*C onto stack = 7*7=49
pop item fron the stack and store in B = B=49
push B+A onto stack = 3+5=8
pop item from the stack and store in A = A=8
pop item for the stacj and sotore in B = B=5
???????????????????/

HELP


your first example
ie
push A onto stack = 5
push C*C onto stack = 49
pop item fron the stack and store in B = B=49
push B+A onto stack = 49+5=54
pop item from the stack and store in A = A=54
pop item for the stack and store in B = B=5

is definetly right..ok
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC