There are still a number of problems with that code.
Your 'x' for loop is not right. Each iteration the size of a or b decreases and x also increases.
You'd be better off using an infinite loop "for(;; )" and "break"ing out of the loop when either stack becomes empty. I also suggest putting the test for an empty stack first so that combining two stacks where one was empty to begin with, also works.
Also, each iteration, one OR two items are added to the unionStack. You should instead make these use an if-else instead:
Code:
if(a.top()<=b.top())
...
if(b.top()<=a.top())
...
becomes:
Code:
if(a.top()<=b.top())
...
else
...
Lastly, you shouldn't use ".size()==0". To specifically test for an empty container you should use ".empty()". Cleaner, and potentially more efficient when all you care about is whether it is zero or not, rather than the exact value.