Simple Queues

by Soong Chong - GUI Computing

I was recently required to keep track of page numbers in the form of a Queue. That is, the first page on the Queue will be the first page off the Queue.

Image of How-To Icon The first method I considered was to keep the page numbers in an array of integers.

A simpler alternative is to use a string to store the page numbers. The pages numbers are formatted in the form "00,". This is, page one will be stored as "01,", page two as "02,". The comma is not necessary to delimit the page numbers in the Queue but makes it the more readable and helps to find elements in the Queue. For example, page numbers 02 and 20 are on the Queue and I check if page number 22 is on the Queue using the INSTR function, "22" will be found in "0220" but not in "02,20,".

Image of How-To Icon The following code illustrates the simpler version of my page number Queue.

A third alternative would be to use a fixed sized array to store the page numbers. This would involve keeping track of the front, the end of the queue and wrapping the page number back to the front when the end of the array has been reached. (More effort than it is worth!).

Written by: Soong Chong
August 1995

Image of arrow to previous article Image of arrow to next article