## `adt::Queue` -- abstract data type ``Queue''

#### Introduction

`adt::Queue` implements the abstract data type ``Queue''.

#### Call(s)

`adt::Queue(queue)`

#### Parameters

`queue` | - | an expression sequence of objects to initialize the queue

#### Returns

an object of the domain `adt::Queue`

#### Details

- `adt::Queue` implements the abstract data type ``Queue''. To create a queue, an expression sequence of any MuPAD objects can be given to initialize the queue, otherwise an empty queue is builded.

- The methods of all abstract datatypes must be called especially and will result changing the object itself as sideeffect.

- With `Q := adt::Queue()` an empty queue is builded and assigned to the variable `Q`.
- Every queue will be displayed as `Queue` followed by a number. This name is generated by `genident`.

- All following methods changes the value of `Q` itself. A new assignment to the variable (in this example `Q`) is not necessary, in contrast to all other MuPAD functions and data types.

- The methods `clear`, `dequeue`, `empty`, `enqueue`, `front`, `length`, `reverse` are available for handling with queues.

- #### Method Q::clear: clear the queue

  - `Q::clear()`
  - - With this method the hole queue will be cleared.

  #### Method Q::dequeue: get an element from the queue

  - `Q::dequeue()`
  - - This method returns the front element of the queue (the first added) with removing it from the queue.

  #### Method Q::empty: is the queue empty

  - `Q::empty()`
  - - This method returns `TRUE`, if no element is in the queue, otherwise `FALSE`.

  #### Method Q::enqueue: fill up the queue

  - `Q::enqueue(x)`
  - - This method puts the element `x` at the end of the queue.

  #### Method Q::front: front of the queue

  - `Q::front()`
  - - This method returns the front element of the queue (the first added) without removing it from the queue.

  #### Method Q::length: length of the queue

  - `Q::length()`
  - - This method returns the number of elements in the queue.

  #### Method Q::reverse: revert the queue

  - `Q::reverse()`
  - - This method reverses the order of all elements in the queue.

#### Example 1

Create a new queue with strings as arguments.

    >> Q := adt::Queue("1", "2", "3", "4")

                                      Queue1

Show the length of the queue.

    >> Q::length()

                                         4

Fill up the queue with a new element. The queue will be changed by the method, no new assignment to `Q` is necessary!

    >> Q::enqueue("5")

                                        "5"

Show the front of the queue. This method does not change the queue.

    >> Q::front(), Q::front()

                                     "1", "1"

After twice getting an element of the queue, the third element is the new front of the queue, and the length is `3`.

    >> Q::dequeue(), Q::dequeue(), Q::front(), Q::length()

                                 "1", "2", "3", 3

Now revert the queue. The last element will be the first element.

    >> Q::reverse(): Q::front()

                                        "5"

Enlarge the queue with `"2"`.

    >> Q::enqueue("2"):
       Q::empty()

                                       FALSE

Finally collect all elements of the queue in the list assigned to `ARGS`, until the queue is empty.

    >> ARGS := []: while not Q::empty() do ARGS := append(ARGS, Q::dequeue()) end:
       ARGS

                               ["5", "4", "3", "2"]

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000