generic datatypes

T

Tony Johansson

Hello!

Here I have declared a queue consisting of ints which is a value type.
This is a queue of ints for example 5 int in the queue 6 7 8 4 7
Queue<int> intQueue = new Queue<int>();

Here I have a queue consisting of queue of ints
Each element in the queue is a queue of ints.
Queue<Queue<int>> queueQueue = new Queue<Queue<int>> ();

Now to my question:
Question number 1: Is it right to say for this declaration
Queue<Queue<int>> queueQueue = new Queue<Queue<int>> ();
that
Each element in the queue is a queue of ints. So if the queue have three
elements you have three queues of ints in the queue ?

Question number 2: When you have a queue consisting of queue of ints I
assume that each element is a reference to the queue
of ints is this right understood? If the queue have three elements then each
element is a reference to the queue of ints right?

//Tony
 
M

Marc Gravell

So if the queue have three
elements you have three queues of ints in the queue ?
Yes [well, 3 references]
Question number 2: When you have a queue consisting of queue of ints I
assume that each element is a reference to the queue
of ints is this right understood? If the queue have three elements then each
element is a reference to the queue of ints right?
Yes; this is simply because Queue<T> is a reference-type (class); the
outer queue is *actually* a queue of references; the inner queue is a
queue of integers (since Int32 is a value-type (struct))

To be honest, though, it seems an unlikely scenario to have a nested
queue, since it is highly likely that once you've dequeued each you
are going to simply process the contents and look for the next - are
you sure that a Queue<int[]> (i.e. a queue where each element is an
array of integers) isn't a better option? Just a thought...

Marc
 
B

Ben Voigt [C++ MVP]

Marc said:
So if the queue have three
elements you have three queues of ints in the queue ?
Yes [well, 3 references]
Question number 2: When you have a queue consisting of queue of ints
I assume that each element is a reference to the queue
of ints is this right understood? If the queue have three elements
then each element is a reference to the queue of ints right?
Yes; this is simply because Queue<T> is a reference-type (class); the
outer queue is *actually* a queue of references; the inner queue is a
queue of integers (since Int32 is a value-type (struct))

To be honest, though, it seems an unlikely scenario to have a nested
queue, since it is highly likely that once you've dequeued each you
are going to simply process the contents and look for the next - are
you sure that a Queue<int[]> (i.e. a queue where each element is an
array of integers) isn't a better option? Just a thought...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top