treeElem(X, t(L, _, _)) :-
    treeElem(X, L).
treeElem(X, t(_,X,_)).
treeElem(X, t(_,_,R)) :-
    treeElem(X, R).

treeDepth(nil, 0).
treeDepth(t(L, _, R), N) :-
    treeDepth(L, NL),
    treeDepth(R, NR),
    N is 1 + max(NL, NR).

treeSize(nil, 0).
treeSize(t(L, _, R), N) :-
    treeSize(L, NL),
    treeSize(R, NR),
    N is NL + NR + 1.

treeTraverse(nil, []).
treeTraverse(t(LeftNode,RootValue,RightNode),List) :-
    treeTraverse(LeftNode, LeftList),
    treeTraverse(RightNode, RightList),
    append(LeftList, [RootValue], LeftList),
    append(LeftList, RightList, List).

treeIsSorted(nil).
treeIsSorted(t(LeftNode,RootValue,RightNode)) :-
    (
        LeftNode = nil;
        (
            LeftNode = t(_,LeftValue,_),
            LeftValue < RootValue,
            treeIsSorted(LeftNode)
        )
    ),
    (
        RightNode = nil;
        (
            RightNode = t(_,RightValue,_),
            RightValue > RootValue,
            treeIsSorted(RightNode)
        )
    ),!.

isList(X) :- var(X),!,fail.
isList([_X|_T]).
isList([]).

na_atomicke([],[]).
na_atomicke([X|T],[FunctorName|FT]) :-
    functor(X, FunctorName, _),
    na_atomicke(T, FT).

customFunctor(Term, Name, Arity) :- 
    Term =.. [Name|Args],
    length(Args, Arity).
 