Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
10
Task/Priority-queue/Mathematica/priority-queue-1.math
Normal file
10
Task/Priority-queue/Mathematica/priority-queue-1.math
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
push = Function[{queue, priority, item},
|
||||
queue = SortBy[Append[queue, {priority, item}], First], HoldFirst];
|
||||
pop = Function[queue,
|
||||
If[Length@queue == 0, Null,
|
||||
With[{item = queue[[-1, 2]]}, queue = Most@queue; item]],
|
||||
HoldFirst];
|
||||
peek = Function[queue,
|
||||
If[Length@queue == 0, Null, Max[queue[[All, 1]]]], HoldFirst];
|
||||
merge = Function[{queue1, queue2},
|
||||
SortBy[Join[queue1, queue2], First], HoldAll];
|
||||
11
Task/Priority-queue/Mathematica/priority-queue-2.math
Normal file
11
Task/Priority-queue/Mathematica/priority-queue-2.math
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
queue = {};
|
||||
push[queue, 3, "Clear drains"];
|
||||
push[queue, 4, "Feed cat"];
|
||||
push[queue, 5, "Make tea"];
|
||||
push[queue, 1, "Solve RC tasks"];
|
||||
push[queue, 2, "Tax return"];
|
||||
Print[peek[queue]];
|
||||
Print[pop[queue]];
|
||||
queue1 = {};
|
||||
push[queue1, 6, "Drink tea"];
|
||||
Print[merge[queue, queue1]];
|
||||
Loading…
Add table
Add a link
Reference in a new issue