Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,14 +1,14 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% definitions of queue
empty(U-V) :-
unify_with_occurs_check(U, V).
unify_with_occurs_check(U, V).
push(Queue, Value, NewQueue) :-
append_dl(Queue, [Value|X]-X, NewQueue).
append_dl(Queue, [Value|X]-X, NewQueue).
pop([X|V]-U, X, V-U) :-
\+empty([X|V]-U).
\+empty([X|V]-U).
@ -17,32 +17,32 @@ append_dl(X-Y, Y-Z, X-Z).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% use of queue
queue :-
% create an empty queue
empty(Q),
format('Create queue ~w~n~n', [Q]),
% create an empty queue
empty(Q),
format('Create queue ~w~n~n', [Q]),
% add numbers 1 and 2
write('Add numbers 1 and 2 : '),
push(Q, 1, Q1),
push(Q1, 2, Q2),
% add numbers 1 and 2
write('Add numbers 1 and 2 : '),
push(Q, 1, Q1),
push(Q1, 2, Q2),
% display queue
format('~w~n~n', [Q2]),
% display queue
format('~w~n~n', [Q2]),
% pop element
pop(Q2, V, Q3),
% pop element
pop(Q2, V, Q3),
% display results
format('Pop : Value ~w Queue : ~w~n~n', [V, Q3]),
% display results
format('Pop : Value ~w Queue : ~w~n~n', [V, Q3]),
% test the queue
write('Test of the queue : '),
( empty(Q3) -> writeln('Queue empy'); writeln('Queue not empty')), nl,
% test the queue
write('Test of the queue : '),
( empty(Q3) -> writeln('Queue empy'); writeln('Queue not empty')), nl,
% pop the elements
write('Pop the queue : '),
pop(Q3, V1, Q4),
format('Value ~w Queue : ~w~n~n', [V1, Q4]),
% pop the elements
write('Pop the queue : '),
pop(Q3, V1, Q4),
format('Value ~w Queue : ~w~n~n', [V1, Q4]),
write('Pop the queue : '),
pop(Q4, _V, _Q5).
write('Pop the queue : '),
pop(Q4, _V, _Q5).