CHAPTER 6. QUEUES
51
Deque’s provide front and back specific versions of common queue operations,
e.g. you may want to enqueue an item to the front of the queue rather than
the back in which case you would use a method with a name along the lines
of
EnqueueFront. The following list identifies operations that are commonly
supported by deque’s:
•
EnqueueFront
•
EnqueueBack
•
DequeueFront
•
DequeueBack
•
PeekFront
•
PeekBack
Figure 6.2 shows a deque after the invocation of the following methods (in-
order):
1.
EnqueueBack(12)
2.
EnqueueFront(1)
3.
EnqueueBack(23)
4.
EnqueueFront(908)
5.
DequeueFront()
6.
DequeueBack()
The operations have a one-to-one translation in terms of behaviour with
those of a normal queue, or priority queue. In some cases the set of algorithms
that add an item to the back of the deque may be named as they are with
normal queues, e.g.
EnqueueBack may simply be called
Enqueue an so on. Some
frameworks also specify explicit behaviour’s that data structures must adhere to.
This is certainly the case in .NET where most collections implement an interface
which requires the data structure to expose a standard
Add method. In such
a scenario you can safely assume that the
Add method will simply enqueue an
item to the back of the deque.
With respect to algorithmic run time complexities a deque is the same as
a normal queue. That is enqueueing an item to the back of a the queue is
Dostları ilə paylaş: