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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -