home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / TRI_INS.LF < prev    next >
Text File  |  1996-06-04  |  2KB  |  49 lines

  1.  
  2. %%%%%%%
  3. % tri par insertion
  4. % Par Christophe Bonnet
  5.  
  6. % Interesting because of use of strip, root_sort, and <- built-ins.
  7.  
  8. %% pour les nombres :
  9.  
  10. n_insert(N,[M|L]) :- N>M, !, n_insert(N,L).
  11. n_insert(N,L) :-
  12.         LL=strip(L) & root_sort(L),% Create a new "head" pointing to attributes.
  13.         L <- [N|LL]. % Insert N at the head of the list.
  14.  
  15. n_tri_ins([],L).
  16. n_tri_ins([A|T],L) :- n_insert(A,L), n_tri_ins(T,L).
  17.  
  18. n_trie_ins(L) -> LL | n_tri_ins(L,LL:[]).
  19.  
  20. %% pour n'importe quel ordre :
  21.  
  22. insert(N,[M|L],Order) :- Order(N,M), !, insert(N,L,Order).
  23. insert(N,L) :-
  24.         LL=strip(L) & root_sort(L),
  25.         L <- [N|LL].
  26.  
  27. tri_ins([],L).
  28. tri_ins([A|T],L,Order) :- insert(A,L,Order), tri_ins(T,L,Order).
  29.  
  30. trie_ins(L,order=>Order) -> LL | tri_ins(L,LL:[],Order).
  31.  
  32. strleq("",string,_,_) -> true.
  33. strleq(string,"",_,_) -> false.
  34. strleq(S1:string,S2:string) -> or(C1:asc(S1) < C2:asc(S2),
  35.                                   and(C1=:=C2,
  36.                                       lenstrleq(substr(S1,2,L1:strlen(S1)),
  37.                                                 substr(S2,2,L2:strlen(S2)),
  38.                                                 L1,L2))).
  39.  
  40. lenstrleq("",string,_,_) -> true.
  41. lenstrleq(string,"",_,_) -> false.
  42. lenstrleq(S1,S2,L1,L2) -> or(C1:asc(S1) < C2:asc(S2),
  43.                              and(C1=:=C2,
  44.                                  lenstrleq(substr(S1,2,LL1:(L1-1)),
  45.                                            substr(S2,2,LL2:(L2-1)),
  46.                                            LL1,LL2))).
  47.  
  48.  
  49.