I have two Integer stacks StackA and StackB.
StackA has the following values but StackB has no content.
StackA
-----
[40]
[11]
[56]
[10]
[11]
[56]
Now i need to copy distinct values from StackA to StackB.I tried this
    public static void CopyDistinctValues(Stack<int> source, Stack<int> destination)
    {
        int[] numArray = source.ToArray();
        for (int i = 0; i < numArray.Length; i++)
        {
            if (!destination.Contains(numArray[i]))
            {
                destination.Push(numArray[i]);
            }
        }
    }
and its working but i am not sure if its the best solution.
Is there a better way to do this or any built in method to achieve this?
It will be better if it can be done without using Array.
 
     
     
     
     
    