Program for finding common elements in stack

I need the steps to proceed for finding common elements in 2 stacks and creating a 3rd stack called common stack with common values from both. Assume that duplicate values are allowed
Hi need help urgent!!!!!!
Are they ordered in any way? If not:

1
2
3
Forall i elemOf stack1
  Forall j elemOf stack2
    if (elem i of stack1 equals elem j of stack2) add to stack3


All you need is the size of stacks 1 and 2 (or at least some way to identify the end).
Look at first value in first stack. Compare it to all values in second stack. If you find a match, copy to third stack and stop comparing.
Repeat for all values in first stack.
Hi, I didn't understand it on implementation part of it, should I use 2 for loops and an if condition.
I'm confused, I'm new to c++ so can you send me the code of match the values in 2 stacks in copying in 3 stack.
No. It sounds like homework, so do it yourself. It's very easy.
Topic archived. No new replies allowed.