balance_tree2.pl

loading
details
attribute value
description
owner Johannes Waldmann
uploaded 2017-08-17 03:45:07.0
disk size 649 Bytes
downloadable true
type
attribute value
name no_type
processor id 1
description this is the default benchmark type for rejected benchmarks and benchmarks that are not associated with a type.
owning community none
loading contents
%query: balance(o,i).
%% file   : balance.pl
%% author : samir genaim
%% date   : 28 Aug, 1998
%%
%% Desc   : balance a binary tree. Works in both directions,
%%          and do it using just once pass on the input.
%%
%%          T = tree(T,Any,T) | nil 
%%

balance(T,TB) :-
	balance(T,I-[],[(TB,I-[])|X]-X,Rest-[],Rest-[]).


balance(nil,X-X,A-B,A-B,[(nil,C-C)|T]-T).
balance(tree(L,V,R),IH-IT,[(tree(LB,VB,RB),A-D)|H]-[(LB,A-[VB|X]),(RB,X-D)|T],HR-TR,NH-NT) :-
        balance(L,IH-[V|IT1],H-T,HR1-TR1,NH-NT1),
        balance(R,IT1-IT,HR1-TR1,HR-TR,NT1-NT).



/*TWDESC

balane a binary tree. work in both directions.

*/

/*TWDEMO

*/
/*.

*/
popout

content may be truncated. 'popout' for larger text window.

actions get anonymous link download benchmark