II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
138 c. A, R, HOARE<br />
redundant informati<strong>on</strong> (e.g. length of previous<br />
the sequence.<br />
f. Stack<br />
~////.~<br />
"//////A<br />
"//////A<br />
]top of stack<br />
I J<br />
. . . . . . . .<br />
Queue<br />
NNt~<br />
(a) (b)<br />
I~ tog or length indicati<strong>on</strong><br />
first free<br />
read pointer<br />
Fie. 6. Sequences (variable length items)<br />
item) between each item in<br />
z////~2A<br />
z/2"//,/A<br />
Deque<br />
(c)<br />
2 length<br />
1 length<br />
5 length<br />
When a sequence is itself a part of an item of some other sequence, the<br />
c<strong>on</strong>tiguous representati<strong>on</strong> of the item-sequence may be used. This will<br />
normally be accompanied by a count giving the length of the sequence, so<br />
that the actual size of each item can be computed when the item is read.<br />
8.2.2. Chained Representati<strong>on</strong><br />
In order to avoid reshuffling problems menti<strong>on</strong>ed in the previous secti<strong>on</strong>, it<br />
is usual to introduce indirect or chained methods of storage allocati<strong>on</strong>, using<br />
either fixed length or variable length units of allocati<strong>on</strong>. The available store<br />
is split into areas, some of which will be in use for storing items of some<br />
sequence, and others will be free. The free areas are also linked together as a<br />
chained sequence. Whenever a programmer's sequence requires extensi<strong>on</strong>,<br />
an area (or part of an area) is acquired from the free chain; and whenever a<br />
sequence is shortened by reading, an area can be returned to the free chain.<br />
In the case of fixed-length items, the administrati<strong>on</strong> of dynamic storage<br />
allocati<strong>on</strong> with explicit deallocati<strong>on</strong> presents no problems. The problems of<br />
variable length allocati<strong>on</strong> will not be treated here; they are best avoided by<br />
the use of blocking (see next secti<strong>on</strong>).<br />
The simplest form of chain is the single linked chain. Each item of the<br />
sequence has adjoined to it, in a link locati<strong>on</strong>, the address of the next item