このディレクトリの索引

merge_sort(L1,L2) :- merge_sort_0(L1,L1_1), merge_sort_1(L1_1,L2). merge_sort_0([],[]). merge_sort_0([A],[[A]]). merge_sort_0([A,B|R1],[[A,B]|R2]) :- A @< B, merge_sort_0(R1,R2). merge_sort_0([A,B|R1],[[B,A]|R2]) :- A @>= B, merge_sort_0(R1,R2). merge_sort_1([L],L) :- !. merge_sort_1(L1,L2) :- merge_sort_2(L1,L1_2), merge_sort_1(L1_2,L2). merge_sort_2([],[]). merge_sort_2([L1],[L1]). merge_sort_2([L1,L2|R1],[L|R2]) :- merge(L1,L2,L), merge_sort_2(R1,R2). merge([],X,X) :- !. merge(X,[],X) :- !. merge([A|R1],[B|R2],[A|R3]) :- A @< B, merge(R1,[B|R2],R3). merge([A|R1],[B|R2],[B|R3]) :- A @>= B, merge([A|R1],R2,R3).