.n個結點的完全二叉樹存儲在數組a中下面為非遞歸的先序遍歷算法
PROC preorder(a);
BEGIN top:=; t:=;
WHILE (t<=n) OR ()______DO
BEGIN WHILE t<=n DO BEGIN write(a[t]); top:=top+; s[top]:=t; t:= ()______;END;
IF top> THEN BEGIN t:=s[top]*+; top:= ()______; END;
END;
END;【中山大學 四 (分)】
.後序遍歷二叉樹的非遞歸算法bt是二叉樹的根S是一個棧maxsize是棧的最大容量
TYPE bitreptr=^bnodetp;
bnodetp=RECORD data:datatype; lchildrchild:bitreptr END;
TYPE stacktyp=RECORD data:ARRAY[maxsize] OF bitreptrtopmaxsizeEND
PROCEDURE posterorder(btbitreptr)
BEGIN Stop:=p:=bt
REPEAT
WHILE p<>NIL DO BEGIN Stop:=Stop+; IF Stop>maxsize THEN stackfull
ELSE BEGIN Sdata[Stop]:=p ()_____; END
END;
IF Sdata[Stop]^rchild<>NIL THEN ()_____
ELSE BEGIN REPEAT write (Sdata[Stop]^data); Stop=Stop;
UNTIL Stop= OR Sdata[Stop]^rchild<>Sdata[Stop+];
IF Sdata[Stop]^rchild<>Sdata[Stop+] THEN ()_____;
END
UNTIL()_____;
END 【西北工業大學 六 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23468.html