home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / brklyprl.lha / Emulator / Benchmarks / qs4.pl < prev    next >
Encoding:
Text File  |  1989-04-14  |  590 b   |  31 lines

  1.  
  2. /* Copyright (C) 1988, 1989 Herve' Touati, Aquarius Project, UC Berkeley */
  3.  
  4. %    quicksort (qs4) on 50 items
  5. %    from Warren's thesis
  6.  
  7. main :-
  8.     list50(L),
  9.     qsort(L,X,[]),
  10.     write(X), nl.
  11.  
  12. qsort([X|L],R,R0) :-
  13.     partition(L,X,L1,L2),
  14.     qsort(L2,R1,R0),
  15.     qsort(L1,R,[X|R1]).
  16. qsort([],R,R).
  17.  
  18. partition([X|L],Y,[X|L1],L2) :-
  19.     X<Y, !,
  20.     partition(L,Y,L1,L2).
  21. partition([X|L],Y,L1,[X|L2]) :-
  22.     partition(L,Y,L1,L2).
  23. partition([],_,[],[]).
  24.  
  25. list50([27,74,17,33,94,18,46,83,65,2,
  26.     32,53,28,85,99,47,28,82,6,11,
  27.     55,29,39,81,90,37,10,0,66,51,
  28.     7,21,85,27,31,63,75,4,95,99,
  29.     11,28,61,74,18,92,40,53,59,8]).
  30.  
  31.