%trace
domains
l=integer*
database
db(integer)
predicates
start
readList(l,integer,l)
printdb
readdb(integer)
marge(l,l)
findMax(l,integer,integer)
findSecondMax(l,integer,integer,integer)
clauses
start:-
write("Enter the 10 list data"),
readList([],1,New),
write(New),
readdb(1),
printdb,
marge(New,Concat),
write(Concat),
findMax(Concat,0,Max),
findSecondMax(Concat,0,Max,SecondM),
write("Second max is::",SecondM).
readList(List,N,New):-
N < 4,
write("\nEnter the ",N," value::"),
readint(Val),
NN=N+1,
Fr = [Val|List],
readList(Fr,NN,New).
readList(List,4,List).
readdb(N):-
N < 4,
write("Enter the ",N," value::"),
readint(Val),
assert(db(Val)),
NN=N+1,
readdb(NN).
readdb(4).
printdb:-
db(Val),
write(Val),
fail.
printdb.
marge(List,Concat):-
retract(db(Value)),
New = [Value| List],
marge(New,Concat).
marge(List,Concat):-
Concat = List.
findMax([Head|List],Max,M):-
Head > Max,
findMax(List,Head,M).
findMax([Head|List],Max,M):-
findMax(List,Max,M).
findMax([],Max,Max).
findSecondMax([Head|List],Zero,Max,SecondM):-
Head < Max and Head > Zero,
findSecondMax(List,Head,Max,SecondM).
findSecondMax([Head|List],Zero,Max,SecondM):-
findSecondMax(List,Zero,Max,SecondM).
findSecondMax([],Zero,Max,Zero).