954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

application of stacks.

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

scias23
Junior Poster in Training
69 posts since Jan 2009
Reputation Points: 11
Solved Threads: 0
 

When you store something in B, that means the predefined value will be overwritten.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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]
...

GPMan
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

Anyway, your first example (where A gets assigned 54) is perfectly right.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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

ajeet choudhary
Newbie Poster
4 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You