tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
18
Task/Priority-queue/PicoLisp/priority-queue-1.l
Normal file
18
Task/Priority-queue/PicoLisp/priority-queue-1.l
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Insert item into priority queue
|
||||
(de insertPQ (Queue Prio Item)
|
||||
(idx Queue (cons Prio Item) T) )
|
||||
|
||||
# Remove and return top item from priority queue
|
||||
(de removePQ (Queue)
|
||||
(cdar (idx Queue (peekPQ Queue) NIL)) )
|
||||
|
||||
# Find top element in priority queue
|
||||
(de peekPQ (Queue)
|
||||
(let V (val Queue)
|
||||
(while (cadr V)
|
||||
(setq V @) )
|
||||
(car V) ) )
|
||||
|
||||
# Merge second queue into first
|
||||
(de mergePQ (Queue1 Queue2)
|
||||
(balance Queue1 (sort (conc (idx Queue1) (idx Queue2)))) )
|
||||
18
Task/Priority-queue/PicoLisp/priority-queue-2.l
Normal file
18
Task/Priority-queue/PicoLisp/priority-queue-2.l
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Two priority queues
|
||||
(off Pq1 Pq2)
|
||||
|
||||
# Insert into first queue
|
||||
(insertPQ 'Pq1 3 '(Clear drains))
|
||||
(insertPQ 'Pq1 4 '(Feed cat))
|
||||
|
||||
# Insert into second queue
|
||||
(insertPQ 'Pq2 5 '(Make tea))
|
||||
(insertPQ 'Pq2 1 '(Solve RC tasks))
|
||||
(insertPQ 'Pq2 2 '(Tax return))
|
||||
|
||||
# Merge second into first queue
|
||||
(mergePQ 'Pq1 'Pq2)
|
||||
|
||||
# Remove and print all items from first queue
|
||||
(while Pq1
|
||||
(println (removePQ 'Pq1)) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue