Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Priority-queue/Clojure/priority-queue.clj
Normal file
19
Task/Priority-queue/Clojure/priority-queue.clj
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
user=> (use 'clojure.data.priority-map)
|
||||
|
||||
; priority-map can be used as a priority queue
|
||||
user=> (def p (priority-map "Clear drains" 3, "Feed cat" 4, "Make tea" 5, "Solve RC tasks" 1))
|
||||
#'user/p
|
||||
user=> p
|
||||
{"Solve RC tasks" 1, "Clear drains" 3, "Feed cat" 4, "Make tea" 5}
|
||||
|
||||
; You can use assoc or conj to add items
|
||||
user=> (assoc p "Tax return" 2)
|
||||
{"Solve RC tasks" 1, "Tax return" 2, "Clear drains" 3, "Feed cat" 4, "Make tea" 5}
|
||||
|
||||
; peek to get first item, pop to give you back the priority-map with the first item removed
|
||||
user=> (peek p)
|
||||
["Solve RC tasks" 1]
|
||||
|
||||
; Merge priority-maps together
|
||||
user=> (into p [["Wax Car" 4]["Paint Fence" 1]["Sand Floor" 3]])
|
||||
{"Solve RC tasks" 1, "Paint Fence" 1, "Clear drains" 3, "Sand Floor" 3, "Wax Car" 4, "Feed cat" 4, "Make tea" 5}
|
||||
Loading…
Add table
Add a link
Reference in a new issue