queue - Maple Help

queue

queue data structure

 Calling Sequence queue[type](obj, 'queue') queue[new]() queue[new](obj1, ..., objn) queue[enqueue](Q, obj) queue[dequeue](Q) queue[empty](Q) queue[front](Q) queue[length](Q) queue[clear](Q) queue[reverse](Q)

Parameters

 Q - queue obj, obj[i] - values to be inserted into the queue

Description

 • Important: The queue command has been deprecated. Use the superseding command DEQueue instead.
 • A queue is a computer science data structure for storing objects that are to be processed in a "first come, first served" order. You place objects in a queue and, later, remove them for processing in the same order that they were placed in the queue. It is analogous to a theater line-up: the first person to arrive at the line is the first person to gain admission. For this reason, queues are often called FIFOs ("first in -- first out").
 • To place objects into a container, and then access them in the opposite order, use a stack.
 • Because you can only add items to the end of a queue, and remove them from the front, operations on queues are very efficient.
 • In Maple, queues are heterogeneous; that is, any valid Maple object may be placed in a queue, and a queue may contain objects of different types. (In the examples, below, a queue containing both strings and integers is used.)
 • In general, you should use only the operations described in this help page to manipulate queues. If you access directly the internal representation of queues, the results of subsequent queue operations are undefined.
 • Use type(obj, 'queue') to test whether a Maple object obj is of type queue.
 • A queue is created initially by using the procedure queue[new]. It returns a queue that is initialized and ready for use. Called with no arguments, new creates an empty queue. You can also create a queue initialized with a number of objects obj1, obj2, ..., objn by invoking new as new(obj1, obj2,..., objn). The queue that is returned will contain exactly the objects obj1, obj2, ..., objn, with obj1 at the front of the queue and objn at the back, and all of the objects in the specified order. The objects obj1, obj2, ..., objn may be Maple objects of any type, and need not all be of the same type.
 • To determine whether there are any objects left in a queue, awaiting processing, you can used the function empty. The call empty(Q) returns true if the queue Q contains no items, and false otherwise. The argument Q must be a queue, returned by a previous call to new.
 • Items may be placed on a queue by using the procedure enqueue. To insert the object obj at the end of a queue Q, you call the procedure as enqueue(Q, obj). The argument Q must be a queue, returned by a previous call to new.
 • To remove the object at the front of a queue Q, use dequeue(Q). If Q is nonempty, the object at the front of Q is returned. It is an error to attempt to remove an item from an empty queue. You should check that your queue is not empty using empty before calling this function. The argument Q must be a queue, returned by a previous call to new.
 • To examine the object at the front of a queue Q, without removing it, use front(Q). If the queue is nonempty, the object at the front of the queue is returned; otherwise, an error is signalled. You should check that your queue is not empty using empty before calling this function. The argument Q must be a queue, returned by a previous call to new.
 • The number of items in a queue Q may be queried using the function length. If Q is a queue, then length(Q) returns the number of items in Q. The argument Q must be a queue, returned by a previous call to new.
 • A queue Q may be cleared (that is, all objects removed from it) with clear(Q). This operation is done in linear time. The argument Q must be a queue, returned by a previous call to new.
 • The order in which items are stored in a queue Q may be reversed using reverse(Q).
 • An implementation of queues as objects is available using the SimpleQueue constructor.
 • To use a queue function, either define that specific function alone by the command with(queue,function), or define all queue functions by the command with(queue).

Examples

 > $\mathrm{with}\left(\mathrm{queue}\right):$
 > $Q≔\mathrm{new}\left("A","B","C"\right):$
 > $\mathrm{enqueue}\left(Q,1\right)$
 ${1}$ (1)
 > $\mathrm{enqueue}\left(Q,2\right)$
 ${2}$ (2)
 > $\mathrm{enqueue}\left(Q,3\right)$
 ${3}$ (3)
 > $\mathrm{length}\left(Q\right)$
 ${6}$ (4)
 > $\mathrm{front}\left(Q\right)$
 ${"A"}$ (5)
 > $\mathrm{dequeue}\left(Q\right)$
 ${"A"}$ (6)
 > $\mathrm{front}\left(Q\right)$
 ${"B"}$ (7)
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{empty}\left(Q\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{dequeue}\left(Q\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${"B"}$
 ${"C"}$
 ${1}$
 ${2}$
 ${3}$ (8)
 > $\mathrm{length}\left(Q\right)$
 ${0}$ (9)
 > $\mathrm{front}\left(Q\right)$
 > $\mathrm{MathFolks}≔\mathrm{new}\left(\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Allan"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Cassidy"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Dave"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"David"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Douglas"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Edgardo"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"James"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Laura"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Laurent"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Michael"\right):$
 > $\mathrm{enqueue}\left(\mathrm{MathFolks},"Terrence"\right):$
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{queue}\left[\mathrm{empty}\right]\left(\mathrm{MathFolks}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{reverse}\left(\mathrm{MathFolks}\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{dequeue}\left(\mathrm{MathFolks}\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${"Terrence"}$
 ${"Allan"}$
 ${"Michael"}$
 ${"Cassidy"}$
 ${"Laurent"}$
 ${"Dave"}$
 ${"Laura"}$
 ${"David"}$
 ${"James"}$
 ${"Douglas"}$
 ${"Edgardo"}$ (10)
 >