The class queue (waiting queue or series) provides a data type that you can use to manage a large number of objects (elements of the queue) as a sequence. The class queue uses the generic data type Variant for its elements. The schematic name FIFO (First in, first out) for the queue illustrates the principle: The element that was first added to the queue is also exited first. All other elements then move one position forward. The comparison of this data structure with a snake in the market is common: The customer who gets in line first is also served first. Then comes the second and so on. Every new customer has to queue up to the end of the line.
The properties of the queue class are listed in the following table:
|.Size||Integer (ReadOnly)||Number of elements of the queue|
|.IsEmpty||Boolean (ReadOnly)||True if there are no elements in the queue, otherwise false|
Table 18.104.22.168.1.1: Properties of the Queue Class
These are the methods of the class Queue:
|Clear ()||Remove all elements|
|Enq (vElement)||Synonym for enqueue (vElement)|
|Enqueue (vElement)||Insertion of a new element (to the end of the queue)|
|Deq ()||Synonym for Dequeue ()|
|Dequeue ()||Remove and return the first element|
|Peek ()||Returns the first element without removing it|
Table 22.214.171.124.2.1: Methods of the Queue Class
Attention: Be careful when using Deq ()! Calling this method changes the queue and returns a value at the same time. If this value is to be used several times, it must be stored in a variable. A further call of Deq () would already return the next element. If you do not want to use a variable, you can also use the Peek () method. But remember to remove the element from the queue with Deq () the last time you used it.
Queues are suitable for displaying a sequence or a sequence of objects. In this sense, it is used in a demonstration project to represent a shell script that is itself only a sequence of commands, reads a shell script selected by the user into a queue, and then interprets the commands as a sequence of a shell. The text of the command and the output of the shell are displayed in the console. The individual commands are not representative.
Note that the shell usually masters some syntactic structures that cannot be understood as sequences. For example, the Bourne-Again-Shell (bash) used in the example can interpret a while control structure. Since a repetition of statements is not a sequence, the queue fails in this case.