Monday, 15 July 2013

data structures - Algorithm on stacks -



data structures - Algorithm on stacks -

using next algorithm

begin initialize stacks s1,s2 force elements stack s1 procedure p(){ while(!s1.isempty()) pushs2(pops1()) } while(!s2.isempty()) print(pops2()) end

then asks question what pseudo code above intended do?what above algorithm works.

i understand how stacks work. , here print outs same thing given input.if a,b,c,d,e input print out a,b,c,d,e.

does algorithm represent significant.what's utilize of writing sort of one?

p() pushes s1 s2 popping s1 , pushing onto s2 until stack empty , ending while loop prints in s2 until empty... seems pretty straight forwards unless missing something.

push() adds item stack.

pop() returns top item stack.

algorithm data-structures stack

No comments:

Post a Comment