II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
NOTES ON DATA STRUCTURING 137<br />
whole of the remaining store available after allocati<strong>on</strong> to other purposes;<br />
and if overflow occurs, the program could not have been run anyway. If<br />
two stacks are required, they can both be accommodated by arranging that<br />
<strong>on</strong>e of them starts at <strong>on</strong>e end of remaining available store and grows upwards,<br />
and the other starts at the other end and grows downwards. If the stacks<br />
meet, the program cannot c<strong>on</strong>tinue.<br />
If many sequences are to be represented, it is possible to set up a scheme<br />
in which they are spread through the remaining available store; and if any<br />
of them grows to meet its neighbour, it is possible to reshuffle some or all<br />
of the sequences, so that they all have sufficient room to grow again for a bit.<br />
For each sequence there must be a base locati<strong>on</strong> pointing to its beginning,<br />
through which that sequence is always addressed. In additi<strong>on</strong>, the acttial<br />
length of the sequence must be stored. The base locati<strong>on</strong> and length of the<br />
neighbouring sequence must always be inspected when the sequence is<br />
extended. When reshuffling takes place, the base locati<strong>on</strong>s of all moved<br />
sequences are updated to point to the new positi<strong>on</strong> of the sequence. This is<br />
quite a useful ad hoc scheme in cases where the reshuffling is known to be<br />
relatively infrequent; otherwise n<strong>on</strong>-c<strong>on</strong>tiguous representati<strong>on</strong>s are to be<br />
preferred.<br />
Fixed iengl'h Stack Queue Queue<br />
( cyclic buffer )<br />
__ [ i [ S j . S i ~ i -~ I] first free ~ first free<br />
Z'// , , j ,<br />
5, t count 4 1<br />
I<br />
used<br />
free<br />
i<br />
[<br />
[<br />
4<br />
' lfree<br />
used<br />
free<br />
(a) (b) (c)<br />
FIG. 5. Sequences (C<strong>on</strong>tiguous representati<strong>on</strong>)<br />
[ f<br />
used<br />
free<br />
used<br />
When the individual items of a sequence are of variable length, there is<br />
usually no need to pad the shorter items out to the maximum length, since<br />
the use of the tag field, or other technique, will indicate the length of any<br />
given item, and this can be used to step the pointer by the right amount<br />
when the item is read. But this requires that the directi<strong>on</strong> of reading be known<br />
at the time of writing, as in a stack or a queue. If reading is to be carried out<br />
from both ends, it will be necessary to ensure that the length of an item can<br />
be deduced from its bottom as well as its top, which will involve storing