13.07.2015 Views

apple-pascal-1.3-manual

apple-pascal-1.3-manual

apple-pascal-1.3-manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1. Starting at the root node, FLIPPY, follow the tree taking only the upperlink from each node, until a node is found whose upper link does notconnect to a further node. The word in this node is the first word,alphabetically, so print it.2. Now follow this node's lower link.o If a node is connected to the link, follow the tree taking only theupper link from each node, until a node is found whose upper linkdoes not connect to a further node. Print that node's word as the nextone in alphabetic order, and repeat step 2.o If no further node is connected to the link, go back down the tree tothe node whose upper link led to this node. Print that node's word asthe next one in alphabetic order, and repeat step 2. (If no link or alower link led to this node, the list is complete.)Remember, to quit this program just press RETURN in response to themessageENTER WORD:Caution: You must press RETURN twice between each word entry(whether or not you wish to see the tree diagrammed). But if you pressRETURN three times, the program is terminated and your list is lostforever.Program TREE contains examples of the following:o Inserting elements into an unbalanced binary tree (INSERTIT)o Retrieving elements in order from such a tree (PRINTTREE)The BALANCED ProgramBALANCED is identical to TREE, except that it stores words by creating abalanced binary tree. It is taken from an example shown on page 215 of thebook Algorithms+ Data Structures= Programs, by Nicklaus Wirth(Prentice-Hall, 1976). An AVL-BALANCED BINARY TREE is rearrangedafter each element insertion to ensure that, of the two branches at anynode, one branch is at most one node longer than the other branch. Thismethod of element insertion is slower than for an unbalanced tree, butsubsequent retrieval of elements is faster.Other Demonstration ProgramsII-307

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!