next up previous contents
Next: Nested recursive structures Up: Describing Structures Previous: Introduction

Recursive Pointer Based Data Structures

Consider a recursive data structure defined in a sequential language, such as C++, see fig. 2.1. The structure stores a value of type Data , and has pointers to two other structures of the same type, giving the definition a recursive nature. A null pointer would indicate that there was no further sub-structures in that direction.


 
Figure 2.1:   Definition and layout of a binary tree structure
\begin{figure}
\begin{verbatim}
class RecStruct {

 Data value;
 RecStruct *dir1...
 ...batim}\begin{center}

\includegraphics {recstruct1.eps}
\end{center}\end{figure}

This particular definition would define a binary tree structure, providing that the sub-structures are distinct from each other, and distinct from the parent structure. Now consider a way to generalise this structure, by allowing the pointers to point to different types of structure.



 

Timothy Lewis
11/12/1997