Naiv sort

Description

Program implements naiv sort algorithm.

Source: Guide to Prolog Programming (on-line tutorial)

Download

Program source code: naiv_sort.pl

Listing

naive_sort(List,Sorted):-perm(List,Sorted),is_sorted(Sorted).
 
is_sorted([]).
is_sorted([_]).
is_sorted([X,Y|T]):-X=<Y,is_sorted([Y|T]).
 
perm(List,[H|Perm]):-delete(H,List,Rest),perm(Rest,Perm).
perm([],[]).
 
delete(X,[X|T],T).
delete(X,[H|T],[H|NT]):-delete(X,T,NT).

Comments

pl/prolog/pllib/naiv_sort.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0