def PQSize = 10; \Maximum number of items priority queue can hold int PQ(PQSize*2), PQI; func Remove; \Remove and return item with highest priority int Min, I, MinI, Item; [if PQI <= 0 then return 0; Min:= -1>>1; I:= PQI; while I > 0 do [I:= I-2; if PQ(I) < Min then [Min:= PQ(I); MinI:= I; ]; ]; Item:= PQ(MinI+1); \get highest priority Item PQI:= PQI-2; PQ(MinI):= PQ(PQI); \replace that Item with last item PQ(MinI+1):= PQ(PQI+1); return Item; ]; proc Insert(Priority, Item); \Insert item into priority queue int Priority, Item; [if PQI >= PQSize*2 then return; PQ(PQI):= Priority; PQ(PQI+1):= Item; PQI:= PQI+2; ]; int Items, I; [Items:= [ [3, "Clear drains"], [4, "Feed cat"], [5, "Make tea"], [1, "Solve RC tasks"], [2, "Tax return"] ]; PQI:= 0; for I:= 0 to 5-1 do Insert(Items(I,0), Items(I,1)); while PQI > 0 do [Text(0, Remove); CrLf(0)]; ]