Advertisement
steffffffan

P2_2

Nov 20th, 2022 (edited)
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.36 KB | None | 0 0
  1. %2.
  2. % a) Sa se sorteze o lista cu pastrarea dublurilor. De ex: [4 2 6 2 3 4]
  3. % => [2 2 3 4 4 6]
  4.  
  5. insert_sorted([],E,[E]):-!.
  6. insert_sorted([H|T],E,[E,H|T]):-E<H,!.
  7. insert_sorted([H|T],E,[H|R]):- E>=H,
  8.     insert_sorted(T,E,R).
  9.  
  10.  
  11. srtlsth([],C,C):-!.
  12. srtlsth([H|T],S,C):-
  13.     insert_sorted(C,H,C1),
  14.     srtlsth(T,S,C1).
  15.  
  16. srtlst(L,R):-srtlsth(L,R,[]).
  17.  
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement