User Tools

Site Tools

k7:k7.3:k7.3.3:start Class Queue class (gb. data)

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. Properties

The properties of the queue class are listed in the following table:

Property Data typeDescription
.SizeInteger (ReadOnly)Number of elements of the queue
.IsEmptyBoolean (ReadOnly)True if there are no elements in the queue, otherwise false

Table Properties of the Queue Class Methods of a Queue Object

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 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. Project for using the class queue

Figure Project Queue

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.




The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k7/k7.3/k7.3.3/start.txt · Last modified: 05.02.2022 (external edit)

Page Tools