Advertisement
steffffffan

P2_3

Nov 20th, 2022 (edited)
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.43 KB | None | 0 0
  1. %3.
  2. % a) Sa se sorteze o lista cu eliminarea dublurilor. De ex: [4 2 6 2 3
  3. % 4] => [2 3 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. insert_sorted([H|T],H,[H|T]). % nu mai inserez daca il gasesc in lista
  10.  
  11.  
  12. srtlsth([],C,C):-!.
  13. srtlsth([H|T],S,C):-
  14.     insert_sorted(C,H,C1),
  15.     srtlsth(T,S,C1).
  16.  
  17. srtlst(L,R):-srtlsth(L,R,[]).
  18.  
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement