23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

A L<strong>in</strong>ked Structure for General Trees<br />

A natural way to realize a tree T is to use a l<strong>in</strong>ked structure, where we represent<br />

each node v of T by a position object (see Figure 7.5a) with the follow<strong>in</strong>g fields:<br />

A reference to the element stored at v, a l<strong>in</strong>k to the parent of v, <strong>and</strong> a some k<strong>in</strong>d of<br />

collection (for example, a list or array) to store l<strong>in</strong>ks to the children of v. If v is the<br />

root of T, then the parent field of v is null. Also, we store a reference to the root of<br />

T <strong>and</strong> the number of nodes of T <strong>in</strong> <strong>in</strong>ternal variables. This structure is<br />

schematically illustrated <strong>in</strong> Figure 7.5b.<br />

382

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

Saved successfully!

Ooh no, something went wrong!