Mike Sigelakis
Mike Sigelakis

Reputation: 23

prolog check if a list is in ascending order

I have an list and I want to check if it is ordered. Can somebody point out my error?

Thanks

taxinomemene([]).
taxinomemene([element1,element2|Tail]):-
        stoixio1>stoixio12,
        taxinomemene([stoixio2|Tail]).

Upvotes: 1

Views: 2597

Answers (1)

Aimee Borda
Aimee Borda

Reputation: 842

What if you have a singleton list and what are stoixio1 and stoixio12? the condition should be in terms of element1 and element2

is_sorted([]).
is_sorted([_]).
is_sorted([X,Y|T]) :-
   X=<Y,
   is_sorted([Y|T]).

Upvotes: 2

Related Questions