< previous page page_307 next page >

Page 307
LISTING 19.1 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
122:
123:
124:    // Tail node is just a sentinel
125:
126:    class TailNode : public Node
127:    {
128:    public:
129:        TailNode(){}
130:        virtual ~TailNode(){}
131:        virtual Node * Insert(Data * theData);
132:        virtual void Show() const { }
133:
134:    private:
135:
136:    };
137:
138:    // If data comes to me, it must be inserted before me
139:    // as I am the tail and NOTHING comes after me
140:    Node * TailNode::Insert(Data * theData)
141:    {
142:        InternalNode * dataNode = new InternalNode(theData, this);
143:        return dataNode;
144:    }
145:
146:    // Head node has no data, it just points
147:    // to the very beginning of the list
148:    class HeadNode : public Node
149:    {
150:    public:
151:        HeadNode();
152:        virtual ~HeadNode() { delete myNext; }
153:        virtual Node * Insert(Data * theData);
154:        virtual void Show() const { myNext->Show(); }
155:    private:
156:        Node * myNext;
157:    };
158:
159:    // As soon as the head is created
160:    // it creates the tail
161:    HeadNode::HeadNode()
162:    {
163:        myNext = new TailNode;
164:    }
165:
166:    // Nothing comes before the head so just
167:    // pass the data on to the next node
168:    Node * HeadNode::Insert(Data * theData)
169:    {
170:        myNext = myNext->Insert(theData);
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_307 next page >

If you like this book, buy it!