prolog: reverse.pl + reverse.sx (naive via append), 6 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
7
lib/prolog/tests/programs/reverse.pl
Normal file
7
lib/prolog/tests/programs/reverse.pl
Normal file
@@ -0,0 +1,7 @@
|
||||
%% reverse/2 — naive reverse via append/3.
|
||||
%% Quadratic — accumulates the reversed prefix one append per cons.
|
||||
reverse([], []).
|
||||
reverse([H|T], R) :- reverse(T, RT), append(RT, [H], R).
|
||||
|
||||
append([], L, L).
|
||||
append([H|T], L, [H|R]) :- append(T, L, R).
|
||||
Reference in New Issue
Block a user