DataType:queue

From the wonderful RedGuides Wiki

A queue is a first-in, first-out data structure. Items Pushed are inserted at the rear, or 'tail' of the queue. Items removed, or Popped are taken from the 'front' of the queue.


This Data Type is referenced in MQ2Collections, and accessed by Top-Level Object(s): queue

Members

Type Member Description
bool IsEmpty True if Count = 0, False otherwise.
Push[string] True if the item was pushed successfully.
int Count Number of items inserted onto the queue.
string Peek False is returned if IsEmpty is true.
Pop

Examples

Sub QueueTest
    /declare q queue

    /echo 'Starting Queue Test'
    /echo 'Queue is Empty: ${q.IsEmpty}'
    
    | Push entries on the queue and pop them off.
    | Note: entries are inserted (Pushed) in and removed
    | (Popped) in the same order. That is, Pushing A, B, C, D, E
    | and then Popping them will return A, B, C, D, E.
    /echo 'Pushing items onto the Queue.'

    /if (!${q.Push[A]}) {
    	/echo 'Queue Push of A failed.'
	/endmacro
    }
    /if (!${q.Push[B]}) {
    	/echo 'Queue Push of B failed.'
	/endmacro
    }
    /if (!${q.Push[C]}) {
    	/echo 'Queue Push of C failed.'
	/endmacro
    }
    /if (!${q.Push[D]}) {
    	/echo 'Queue Push of D failed.'
	/endmacro
    }
    /if (!${q.Push[E]}) {
    	/echo 'Queue Push of E failed.'
	/endmacro
    }

    /declare count int
    /varset count ${q.Count}
    /if (${count} != 5) {
    	/echo 'Queue count is: ${count} and should be 5.'
	/endmacro
    }

    /echo 'Queue is Empty: ${q.IsEmpty}'
    
    | Peek at the front item:
    /echo 'Front item is: ${q.Peek}'
    
    | Pop items off the queue.

    /echo 'Popping item off queue: ${q.Pop}'
    /echo 'Popping item off queue: ${q.Pop}'
    /echo 'Popping item off queue: ${q.Pop}'
    /echo 'Popping item off queue: ${q.Pop}'
    /echo 'Popping item off queue: ${q.Pop}'

    /echo 'Queue is Empty: ${q.IsEmpty}'
    /echo 'Ending Queue Test'
    
    /return

Notes

  • Pop decreases Count by 1 unless IsEmpty is true.
  • Push increases Count by 1. IsEmpty will never be true after calling Push.
  • Peek retrieves the oldest element Pushed onto the queue. Count is not modified by calling Peek.

See also