Advertisement
sherry_ahmos

Untitled

May 9th, 2023
2,402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.32 KB | None | 0 0
  1. ssort([],[]).
  2. ssort([M1|S],[H|T]):-min(H,T,M1),remove(M1,[H|T],N),ssort(S,N).
  3.  
  4. min(M,[],M).
  5. min(M,[H|T],M1):-min2(M,H,N),min(N,T,M1).
  6.  
  7. min2(A,B,A):-less(A,B).
  8. min2(A,B,B):-not(less(A,B)).
  9.  
  10. less(A,B):-(A<B).
  11.  
  12. append([],B,B).
  13. append([H|A],B,[H|AB]):-append(A,B,AB).
  14.  
  15. remove(X,L,N):-append(A,[X|B],L),append(A,B,N).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement