quicksort( +List, ?SortedList, +CompareTerm )

Sort a list (first argument) using the supplied term for comparing the elements in the unsorted list (third argument). The sorted list will be unified with the second parameter.

This predicate is located in the file 'list.txt', use ensure_loaded/1 to include this file.

see also: conc/3 del/3 largest_number/2 last/2 lengthlist/2 member/2 reverse/2 smallest_number/2 sublist/2 suffix/2 sum_list/2 sum_list_integer/2

%In the examples below the following compare term is used:
  compare_weight( X, Y)  :-
    X =< Y,
    !.

 

Example
quicksort([78, 72, 56, 100], SL, compare_weight). succeeds and the variable SL is unified with a sorted list which is:
SL=[56, 72, 78, 100]
quicksort([78, 72], [78, 72], compare_weight). fails because the sorted list is [72, 78] and that list cannot be unified with the second parameter which is [78, 72]

 

 

info@trinc-prolog.com