full_adder wrote:
Stack is Ok if the path is straightline one by one
i.e., the next point depends on the previuos one
but in the mentiond example , the matter is different
a calls b
b calls c
c replies i.e., to b
b replies i.e., to a
a calls d
d calls c
c replies i.e., to d
d calls e
e replies i.e., to d
d replies i.e, to a
a calls f
f replies i.e., to a
a, b, c, -, -, d, c, -, e, -, -,f,-
Stack tracing: (n dashes requires n+1 pops s.t. the first pop is discarded)
operation stack cont.
---------- --------------------
push(a) a
push(b) a,b
push(c) a,b,c
pop (discarded) a,b
pop a
pop <empty>
push(d) d
push(c) d,c
pop (discarded) d
pop <empty>
push(e) e
pop (discarded)
pop <empty>
pop <empty>
push(f) f
pop <empty>
If we print out the result of each operation to the screen
a,b,c,b,a,d,c,d,e,f
the right path is: a,b,c,b,a,d,c,d,e,d,a,f,a
What do you think?
full_adder
You want a temporary variable ("at") too. So when you get a,b,c,... you first push whatever on "at" to the stack, and let your "at" holds the new point name. When you encounter a "-" you pop to "at".
So taking your example "a, b, c, -, -, d, c, -, e, -, -, f, -", it looks like
Code:
path stack at
------ ------------ ----------
a (empty) a
b a b
c a,b c
- a b
- (empty) a
d a d
c a,d c
- a d
e a,d e
- a d
- (empty) a
f a f
- (empty) a