Compare 2 queues and find an item that does not exist in both queues

advertisements

I'm currently trying to compare 2 queues. Most of the entries in the queue will be duplicate (both queues will have the same entries). What I want to be able to do is, find an entry that does not exist in both queues.

For example, assuming the following are the 2 queues in question.

1st queue - A S D F G
2nd queue - S A D G Q

The entry A, S, D, G exists in both queue. However, the entry F is unique for the 1st queue, and Q is unique for the 2nd queue. I want to be able to find out which entries are unique. Is there a function that does something like this?

For the sake of the question, I need to use a queue as the FIFO behavior is crucial.


var firstQueue = new  Queue<char>() {};
var secondQueue = new Queue<char>() {};

foreach (char obj in firstQueue)
{
    if (!secondQueue.Contains(obj))
    {
        // Doesn't exist in the second queue -> Do something
    }
}

A shorter way of doing it is using LINQ:

// Will contain all the values that secondQueue doesn't contain.
var exampleOne = firstQueue.Except(secondQueue);

// Will contain all the values that firstQueue doesn't contain.
var exampleTwo = secondQueue.Except(firstQueue);

// Will contain all the values that both queues have in common.
var exampleThree = firstQueue.Intersect(secondQueue);