val kante=(3,4,5);
val graph=[(1,2,20),(1,3,23),(1,4,1),(2,4,4),(2,5,15),(3,4,36),(3,6,28),
(4,5,9),(4,7,16),(4,6,25),(5,7,3),(6,7,17)];
val graph1=[(1,3,23),(1,4,1),(2,4,4),(4,5,9),(5,7,3),(6,7,17)];
val geripp=[(1,4,1),(2,4,4),(4,5,9),(5,7,3)];
fun blaetter((baum:(int*int*int) list),i:int,j:int,s:int) =
if s=1
then
if i<= length(baum) andalso j<=length(baum) then if i<>j
then
if ((#1(nth(baum,(j-1))) <> #1(nth(baum,(i-1)))) andalso
(#1(nth(baum,(j-1))) <> #2(nth(baum,(i-1)))))
then
if ((i=length(baum)) orelse
(j=length(baum) andalso i=(length(baum)-1)))
then [nth(baum,j-1)]@blaetter(baum,1,j+1,1)
else blaetter(baum,i+1,j,1)
else blaetter(baum,1,j+1,1)
else blaetter(baum,i+1,j,1)
else blaetter(baum,1,1,2)
else
if i<= length(baum) andalso j<=length(baum) then if i<>j
then
if ((#2(nth(baum,(j-1))) <> #1(nth(baum,(i-1)))) andalso
(#2(nth(baum,(j-1))) <> #2(nth(baum,(i-1)))))
then
if ((i=length(baum)) orelse
(j=length(baum) andalso i=(length(baum)-1)))
then [nth(baum,j-1)]@blaetter(baum,1,j+1,2)
else blaetter(baum,i+1,j,2)
else blaetter(baum,1,j+1,2)
else blaetter(baum,i+1,j,2)
else [];
fun blaetterp ((baum:(int*int*int) list),i:int,j:int,s:int) =
if s=1
then
if i<= length(baum) andalso j<=length(baum) then if i<>j
then
if ((#1(nth(baum,(j-1))) <> #1(nth(baum,(i-1)))) andalso
(#1(nth(baum,(j-1))) <> #2(nth(baum,(i-1)))))
then
if ((i=length(baum)) orelse
(j=length(baum) andalso i=(length(baum)-1)))
then [(#2(nth(baum,j-1)))]@blaetterp(baum,1,j+1,1)
else blaetterp(baum,i+1,j,1)
else blaetterp(baum,1,j+1,1)
else blaetterp(baum,i+1,j,1)
else blaetterp(baum,1,1,2)
else
if i<= length(baum) andalso j<=length(baum) then if i<>j
then
if ((#2(nth(baum,(j-1))) <> #1(nth(baum,(i-1)))) andalso
(#2(nth(baum,(j-1))) <> #2(nth(baum,(i-1)))))
then
if ((i=length(baum)) orelse
(j=length(baum) andalso i=(length(baum)-1)))
then [(#1(nth(baum,j-1)))]@blaetterp(baum,1,j+1,2)
else blaetterp(baum,i+1,j,2)
else blaetterp(baum,1,j+1,2)
else blaetterp(baum,i+1,j,2)
else [];
fun ALPHA(liste:(int*int*int) list,element:(int*int*int))=
if tl(liste)=[]
then if hd(liste)=element
then []
else [hd(liste)]
else if hd(liste)=element
then tl(liste)
else hd(liste)::ALPHA(tl(liste),element);
fun blatt(nr:int,baum:(int*int*int) list,i:int) =
if i<= length(baum) then if ((nr=(#1(nth(baum,i-1)))) orelse (nr=(#2(nth(baum,i-1))))) then nth(baum,i-1) else blatt(nr,baum,(i+1)) else (0,0,0); fun allesweg(blaetterliste:(int*int*int)list,baum:(int*int*int)list)=if length(blaetterliste)<>0
then
allesweg(tl(blaetterliste),ALPHA(baum,hd(blaetterliste)))
else
#2(hd(baum));