18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

This routine, when called by a statement such as call DESTROY(TREE), calls upon itself as each<br />

node destroys the nodes below it. Because each node either points to a successor node or is zero,<br />

the routine can tell whether it has to follow a downward path to destroy successor nodes, or whether<br />

it can destroy the node it is working on by releasing it. Perhaps the easiest way to understand this<br />

routine is to construct a typical tree, such as that shown in figure 2-7, and follow the logic through.<br />

Figure 2-7. A Binary Tree<br />

By changing one statement, as shown below, the routine can easily be expanded to destroy not only<br />

binary trees, but those containing limitless branches as well:<br />

routine DESTROY(NODE)<br />

normally mode is integer<br />

define NODE as a 1-dimensional array<br />

if NODE(*) is not zero,<br />

for BRANCH = 1 to dim.f(NODE(*))<br />

call DESTROY(NODE(BRANCH))<br />

release NODE(*)<br />

always<br />

return<br />

end<br />

80

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

Saved successfully!

Ooh no, something went wrong!