Information about the unit trees.pas writen by Andrei Korobeinik and Dmitri Lepp. The unit is made to work with 'trees' - a kind of data structures. SPECIFICATIONS The structure of the input file. The input file consists of n lines. At each line there is an information about one node of the binary tree. It looks like A B C D or A B C D E so E is an optional parameter. All the elements are separated by exactly one blank. A - integer (not 0!). It is an unique label of the current node (i.e the label of its line). Won't be used in the program. B - integer. The 'key' value of the node. C - integer. It is the label of the left child of the node. If 0, then the left child of this node is missing. D - integer. It is the label of the right child of the node. If 0, then the right child of this node is missing. E - string of length <= MAX_INFO (set to 20). Contains the additional info for the node. The deafult value (if E is missing) is an empty string. The structure of representation in memory. The representation of a binary tree of n nodes consists of n records. Each record contains 6 fields: key - integer. The 'key' value of the node. left - pointer to the left child of the node (or NIL if the left child is missing). right - pointer to the right child of the node (or NIL if the right child is missing). str_info - string of length <= MAX_INFO (set to 20). Contains the additional info for the node. x - integer. A field of free use (any informational for the node). y - integer. A field of free use (any informational for the node). DESCRIPTION The unit contains four functions and procedures. To do with it, print 'uses trees;' in the beginning of the program and you can include into your program all the functions and procedures described below. Example of the input file is in inp.txt. Example of the unit's usage is in demo.pas. The tipe of a pointer to any node (to the root of tree, for example) is pnode. function ReadBinaryTree(filename:string):pnode. Reads data about the binary tree from the input file (filename) and converts it into the structure in memory (read specifications). Returns the pointer to the root of the tree (or NIL, if the tree is empty). Assumes that the input file can't contain more than MAX_N lines (set to 1000). procedure WriteBinaryTree(filename:string,tree:pnode). Writes the binary tree (tree - pointer to its root) from memory to the output file (filename) with format described before. function DisplayBinaryTree(tree:pnode,left,height:integer):integer. Displays the binary tree (tree - pointer to its root) at the screen. Parameters left and height are coordinates of the beginning of the output. procedure DisplayTree(tree:pnode). Displays the usual tree at the screen. Uses its binary representation from memory (tree - pointer to the root of this binary tree). The output begins in the left higher corner. The children of any node are all the nodes which lie at the next lower line from this node, to the right of it and to the left of its right collegue. ERRORS MESSAGES There are some errors which can be processed by unit. All the others are checked by Pascal or won't be checked at all. To get the code of the errors described below, use DOS unit (they can be returned by HALT). 1: Error opening input file! Something wrong with the input file. Wrong name, for example... 2: Wrong reference to a! Error in the input file. There is a pointer to the node with number a, but the node doesn't exist. 3: The tree is too high! and 4: The tree is to wide! There is not enough place at the screen for the tree in DisplayTree procedure. 5: Error opening output file! Something wrong with your disk. Not enough place, for example, or you can't write to this disk.