
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.
 Illustration of FIFO behavior
Task

Create a queue data structure and demonstrate its operations.

(For implementations of queues, see the FIFO task.)



Operations:

   push       (aka enqueue) - add element
   pop         (aka dequeue) - pop first element
   empty     - return truth value when empty


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


 
[System.Collections.ArrayList]$queue = @()
# isEmpty?
if ($queue.Count -eq 0) {
    "isEmpty? result : the queue is empty"
} else {
    "isEmpty? result : the queue is not empty"
}
"the queue contains : $queue"
$queue += 1                    # push
"push result : $queue"
$queue += 2                    # push
$queue += 3                    # push
"push result : $queue"
 
$queue.RemoveAt(0)             # pop
"pop result : $queue"
 
$queue.RemoveAt(0)             # pop
"pop result : $queue"
 
if ($queue.Count -eq 0) {
    "isEmpty? result : the queue is empty"
} else {
    "isEmpty? result : the queue is not empty"
}
"the queue contains : $queue"
 