Question about a Queue object
I have a Queue object with filenames in it. Under certain circumstances I want to move the item at the beginning of the Queue to the end. Will the following line achieve this?
Code:
myFiles.Enqueue(myFiles.Dequeue)
Or is there a better way to do it? Thanks...
Re: Question about a Queue object
Quote:
Originally Posted by
nbrege
Or is there a better way to do it? Thanks...
Nope....that way is the most elegant way I can think of. Its actually pretty clever.
Re: Question about a Queue object
OK, thanks. I didn't see any direct methods for changing the order of items in a Queue, so that's the only way I could see to do it.
Re: Question about a Queue object
Though I have never used Queue objects before, it would seem its practically identically to a List. A List is easy to treat as a first in first out collection.
Re: Question about a Queue object
Quote:
Originally Posted by
Niya
Though I have never used Queue objects before, it would seem its practically identically to a List. A List is easy to treat as a first in first out collection.
Except a Queue actually enforces FIFO behaviour, and can have multiple enqueuers and dequeuers working concurrently without additional synchronisation. If your design calls for FIFO behaviour, favour Queues over Lists.