Spis treści

List max element

Description

Finding greates element from list

Source: PROLOG str. 197 Wydawnictwo PLJ Warszawa 1991 ISBN 83-85190-63-5

Download

Program source code: list_max_element.pl

Listing

max([H|[]], H).
max([H|T], Maximum) :- max(T, M1), mx(H, M1, Maximum), !.
mx(X, Y, X) :- X > Y.
mx(X, Y, Y) :- X =< Y.
 
test :- max([6, 2, 5, 4, 8], M).

Comments