// PriorityQueue.script set Tasks to a new PriorityQueue tell Tasks to add 3,"Clear drains" tell Tasks to add 4,"Feed cat" tell Tasks to add 5,"Make tea" tell Tasks to add 1,"Solve RC tasks" tell Tasks to add 2,"Tax return" put "Initial tasks:" put Tasks.report & return put Tasks.getTop into topItem put "Top priority: " & topItem & return put "Remaining:" & return & Tasks.report ------ properties queue:[] end properties to add newPriority, newTask repeat with each item of my queue if newPriority comes before the priority of it then insert {priority:newPriority, task:newTask} before item the counter of my queue return end if end repeat insert {priority:newPriority, task:newTask} into my queue -- add at end if last priority end add to getTop pull my queue into firstItem return firstItem end getTop to report return (priority of each && task of each for each item of my queue) joined by return end report