Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Priority-queue/Prolog/priority-queue.pro
Normal file
28
Task/Priority-queue/Prolog/priority-queue.pro
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
priority-queue :-
|
||||
TL0 = [3-'Clear drains',
|
||||
4-'Feed cat'],
|
||||
|
||||
% we can create a priority queue from a list
|
||||
list_to_heap(TL0, Heap0),
|
||||
|
||||
% alternatively we can start from an empty queue
|
||||
% get from empty_heap/1.
|
||||
|
||||
% now we add the other elements
|
||||
add_to_heap(Heap0, 5, 'Make tea', Heap1),
|
||||
add_to_heap(Heap1, 1, 'Solve RC tasks', Heap2),
|
||||
add_to_heap(Heap2, 2, 'Tax return', Heap3),
|
||||
|
||||
% we list the content of the heap:
|
||||
heap_to_list(Heap3, TL1),
|
||||
writeln('Content of the queue'), maplist(writeln, TL1),
|
||||
nl,
|
||||
|
||||
% now we retrieve the minimum-priority pair
|
||||
get_from_heap(Heap3, Priority, Key, Heap4),
|
||||
format('Retrieve top of the queue : Priority ~w, Element ~w~n', [Priority, Key]),
|
||||
nl,
|
||||
|
||||
% we list the content of the heap:
|
||||
heap_to_list(Heap4, TL2),
|
||||
writeln('Content of the queue'), maplist(writeln, TL2).
|
||||
Loading…
Add table
Add a link
Reference in a new issue