Example how to use predsort(:Compare, +List, -Sorted) in prolog
问题 I want to order a custom list. The list I want to order will be in this form... [n(_,2,_),n(_,1,_),n(_,3,_)] I have wrote a comparator cheaper(n(_,C1,_),n(_,C2,_)) :- C1>C2. How do I use this with predsort. I wrote a sorting algorithm using bubble sort, but I have very large lists so it very slow. Is it possible to do predsort(cheaper, [n(_,2,_),n(_,1,_),n(_,3,_)] , X). Thank you :) 回答1: Try this : cheaper(>, n(_,C1,_),n(_,C2,_)) :- C1>C2. cheaper(<, n(_,C1,_),n(_,C2,_)) :- C1<C2. cheaper(=,