algorithm - Adding all values of 2 stacks to 1 stack and sorting them -
there 3 stacks - a, b, c
stacks , b sorted (the number on top of stack biggest). stack c empty 5 operation allowed:
push pop top is_empty create
we need write function receives stacks , b, moves numbers in stacks , b stack c , stack c must sorted (biggest number on top).
for first cut, split problem 2 parts:
- move elements , b c, least element being @ top.
- convert c least element @ top c highest element @ top i.e. reverse sort order.
once have this, can see if there better/more efficient algorithm.
Comments
Post a Comment