SimpleQueue - Maple Programming Help

Home : Support : Online Help : Programming : Operations : Queues : SimpleQueue

SimpleQueue

the basic queue constructor

 Calling Sequence SimpleQueue(e1, e2, ..., en) type(e::anything, 'Queue') q:-enqueue(e::anything) q:-dequeue() q:-empty() q:-front() q:-length() q:-clear()   \$include Enqueue(q::Queue, e::anything)::anything Dequeue(q::Queue)::anything Front(q::Queue)::anything EmptyP(q::Queue)::anything

Parameters

 ei - (optional) arbitrary Maple expression (not an expression sequence) q - queue returned by SimpleQueue e - arbitrary Maple expression (not an expression sequence)

Description

 • The procedure SimpleQueue is a queue constructor. It returns a Maple expression that implements a queue object, which is of type Queue.
 The SimpleQueue(e1, e2, ..., en) calling sequence constructs a queue containing the items e1, e2, ..., en. The item e1 is at the front of the queue.
 • You can test whether a Maple expression e is a Queue object by using type(e, 'Queue'). An expression is of type Queue if it is an object with the methods empty, front, enqueue, and dequeue. Specific Queue implementations may support additional methods, but all Queues support at least these four methods. Queues built by the constructor SimpleQueue are currently represented by modules, so the message-passing syntax uses the :- operator.
 • The empty method returns the value true if no items are on the queue, and returns the value false otherwise.
 • To insert an item e (any Maple expression) at the back of a queue, use the enqueue method. The inserted value is returned.
 • Items may be removed from the front of the queue by using the dequeue method. An error is raised if the queue is empty. This error may be caught using the exception string "empty queue".
 • The item at the front of a non-empty queue may be examined, without changing the contents of the queue, by using the method front. If the queue is non-empty, this method returns the item at the front of the queue (the value that will be returned by the next call to the dequeue method), and raises the "empty queue" exception otherwise.
 • Queues constructed by the SimpleQueue constructor also support the methods length, which returns the number of items on the queue, and clear, which empties the queue.
 • The standard include file  defines several inline procedures for invoking the basic Queue operations. The procedures provided are Enqueue, Dequeue, EmptyP, and Front. These procedures are not part of the Maple library, and are provided only as inlined procedures. (Note: The include file  also provides an EmptyP inlined procedure, but it is compatible with the one in , so both include files may be used in the same Maple source file.
 • For a non-object-oriented queue implementation, see the queue package.

Examples

 > $Q≔\mathrm{SimpleQueue}\left(\right):$
 > $\mathrm{type}\left(Q,'\mathrm{Queue}'\right)$
 ${\mathrm{true}}$ (1)
 > $Q:-\mathrm{enqueue}\left(1\right);$$Q:-\mathrm{enqueue}\left(2\right);$$Q:-\mathrm{enqueue}\left(3\right)$
 ${1}$
 ${2}$
 ${3}$ (2)
 > $Q:-\mathrm{length}\left(\right)$
 ${3}$ (3)
 > $Q:-\mathrm{front}\left(\right)$
 ${1}$ (4)
 > $Q:-\mathrm{dequeue}\left(\right)$
 ${1}$ (5)
 > $Q:-\mathrm{front}\left(\right)$
 ${2}$ (6)
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}Q:-\mathrm{empty}\left(\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}}Q:-\mathrm{dequeue}\left(\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${3}$ (7)
 > $Q:-\mathrm{length}\left(\right)$
 ${0}$ (8)
 > $Q:-\mathrm{front}\left(\right)$
 > $\mathrm{MathFolks}≔\mathrm{SimpleQueue}\left(\right):$
 > $\mathrm{MathFolks}:-\mathrm{enqueue}\left("Alex"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Allan"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Dave"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("David"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Edgardo"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("James"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Juergen"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Laurent"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Michael"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Paulina"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Raqeeb"\right):$$\mathrm{MathFolks}:-\mathrm{enqueue}\left("Stephen"\right):$$\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{MathFolks}:-\mathrm{empty}\left(\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{MathFolks}:-\mathrm{dequeue}\left(\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${"Stephen"}$ (9)