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>Programming</strong> <strong>Language</strong> Concepts<br />

normally mode is integer<br />

define NOD and NODE as 1-dimensional arrays<br />

reserve NODE(*) as 2<br />

let TREE = NODE(*)<br />

let NODE(*) = 0<br />

reserve NODE(*) as 2<br />

let NOD(*) = TREE<br />

let NOD(1) = NODE(*)<br />

let NODE(*) = 0<br />

reserve NODE(*) as 2<br />

let NOD(2) = NODE(*)<br />

let NODE(*) = 0<br />

:<br />

end<br />

NOD is used as a dummy array name to which a previous NODE pointer is assigned to allow nodes to<br />

connect to the nodes above them in the tree. This is not the most efficient way to process such trees.<br />

The tree constructed by the program above is illustrated in figure 2-6.<br />

TREE<br />

NODE(1) NODE(2)<br />

NODE(1) NODE(2) NODE(1) NODE(2)<br />

et cetera et cetera et cetera et cetera<br />

Figure 2-6. Tree Construction<br />

A recursive routine to destroy such a tree is shown below. Given the pointer to the root of the tree,<br />

the routine follows all paths in the tree and destroys the nodes on them:<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 2<br />

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

release NODE(*)<br />

always<br />

return<br />

end<br />

79

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

Saved successfully!

Ooh no, something went wrong!