Advertisement
przemko

Korutyny -- sieć sortująca

Jun 12th, 2017
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.55 KB | None | 0 0
  1. % mysort.pl
  2.  
  3. mysort(IN, OUT) :-
  4.     freeze(IN,
  5.            (   IN = [H | IN_]
  6.            ->  filter(H, IN_, OUT1, IN2, OUT),
  7.                mysort(OUT1, IN2)
  8.            ;   OUT = [])).
  9.  
  10. filter(Acc, IN1, OUT1, IN2, OUT2) :-
  11.     freeze(IN1,
  12.            (   IN1 = [H | IN1_]
  13.            ->  (   H >= Acc
  14.                ->  OUT1 = [H | OUT1_],
  15.                    filter(Acc, IN1_, OUT1_, IN2, OUT2)
  16.                ;   OUT1 = [Acc | OUT1_],
  17.                    filter(H, IN1_, OUT1_, IN2, OUT2))
  18.            ;   OUT1 = [],
  19.                OUT2 = [Acc | IN2])).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement