(**************************************** * Description: * AVL-Baum einlesen und dump * im Format für texitree * Author: * Daniel Hottinger * Department of Computer Science, ETH Zurich * SS 2001 * Licence: GNU GPL v2 or later * Created: Tue May 15 11:12:23 CEST 2001 * Last update: none * Changes: ****************************************) MODULE TestAVL; IMPORT AVLTree, Files, Out; TYPE PIntKey = POINTER TO TIntKey; TIntKey = RECORD(AVLTree.TKey) Value: LONGINT; END; PROCEDURE Print(key: AVLTree.PKey); BEGIN Out.Int(key(PIntKey).Value, 2); END Print; PROCEDURE Compare(key1, key2: AVLTree.PKey): LONGINT; BEGIN WITH key1: PIntKey DO WITH key2: PIntKey DO IF key1.Value < key2.Value THEN RETURN -1 ELSIF key1.Value > key2.Value THEN RETURN 1 ELSE RETURN 0 END; END; END; END Compare; PROCEDURE NewVal(val: LONGINT): PIntKey; VAR p: PIntKey; BEGIN NEW(p); p^.Value := val; RETURN p; END NewVal; PROCEDURE Test*; VAR tree: AVLTree.PAVLTree; f: Files.File; r: Files.Rider; l: LONGINT; c: CHAR; BEGIN tree := AVLTree.NewTree(Compare); f := Files.Old("in.txt"); Files.Set(r, f, 0); Files.Read(r, c); WHILE ~ r.eof DO (* Zahl einlesen *) l := 0; WHILE (c # 0AX) & ~ r.eof DO l := l * 10 + ORD(c) - ORD("0"); Files.Read(r, c); END; Files.Read(r, c); AVLTree.Insert(tree, NewVal(l), NIL); AVLTree.Dump(tree, Print); IF ~r.eof THEN Out.String(" =>"); END; Out.Ln; END; Files.Close(f); AVLTree.DestroyTree(tree); END Test; END TestAVL.