 priqueue - Maple Programming Help

Home : Support : Online Help : Programming : Operations : Queues : priqueue

priqueue

priority queue functions

 Calling Sequence priqueue[initialize](pq) priqueue[insert](NewRecord, pq) priqueue[extract](pq)

Parameters

 pq - name of the priority queue NewRecord - structure to be inserted in the queue

Description

 • The initialize function  makes the necessary assignments (side effects) so that the queue pq is initialized with an empty queue. The queue pq is treated as an unbounded array of the inserted records. Additionally, pq$\left[0\right]$ maintains the number of entries in the queue.
 • The insert function adds an element to the queue. The queue is a maximum queue, that is, the maximum element is kept on the head of the queue. The criteria for ordering the queue is giving by NewRecord$\left[1\right]$ and hence this value should exist and be comparable.
 • The extract function returns the stored record with the highest value (in its first position) and deletes this record from the queue.
 • Multiple priority queues are allowed.
 • If inspection alone is desired, the maximum element of the queue is always at pq$\left[1\right]$.
 • To use a priqueue function, either define that specific function alone by the command with(priqueue,function), or define all priqueue functions by the command with(priqueue).

Examples

 > $\mathrm{with}\left(\mathrm{priqueue}\right):$
 > $\mathrm{initialize}\left(\mathrm{DailyTemps}\right)$
 ${0}$ (1)
 > $\mathrm{insert}\left(\left[14,\mathrm{Apr30}\right],\mathrm{DailyTemps}\right)$
 > $\mathrm{insert}\left(\left[24,\mathrm{May4}\right],\mathrm{DailyTemps}\right)$
 > $\mathrm{extract}\left(\mathrm{DailyTemps}\right)$
 $\left[{24}{,}{\mathrm{May4}}\right]$ (2)
 > $\mathrm{extract}\left(\mathrm{DailyTemps}\right)$
 $\left[{14}{,}{\mathrm{Apr30}}\right]$ (3)