The original book is much more content, and at least a lot relative to the circular chain list. I believe that when you make a single-stranded pointer domain, this part should be difficult to fall. Now my question is, can you send two-way linked list from a single-link table?
You can have several practices:
One is to define a double-link node - but, its name must be called node, this is something wrong; otherwise you have to copy a single-link realization file, put the Node all to your double The name of the link, but this is not called inherited.
Another approach is to define a structure for example:
Template
{
PUBLIC:
TYPE DATA;
Node
}
When you derive a two-way linked list, you write Template
Before starting your bidirectional linked list, you want to add the interface to the current pointer and the current forward-drive pointer to the base class, as shown below:
protected:
Void Put (Node
{
Current = P;
}
Void Putprior (Node
{
PRIOR = P;
}
Because this interface is very dangerous, it is almost not available, so I have not given it in front, but I have to complete the two-way linked list of "outstanding" advantages - moving the current pointer forward, must be used. In addition, I have never planned from a single-link watch to derive double-linked list, below you will see that this process is very annoying, or even rewriting a provincial thing, the effectiveness is not very good, this labor force What does it mean to do if it does not want? Indeed, I also think I am in the rhombus. (Don't take me with eggs)
Definition and implementation
#ifndef dbllist_h
#define dbllist_h
#include "list.h"
Template
{
PUBLIC:
TYPE * GET ()
{
IF (Pget ()! = null) Return & Pget () -> Data.Data;
Else Return NULL;
}
TYPE * NEXT ()
{
PNEXT ();
Return get ();
}
TYPE * PRIOR ()
{
IF (PgetPrior! = NULL)
{
PUT (PgetPrior ());
Putprior (Node
Return get ();
}
Return NULL;
}
Void insert (const type & value)
{
Node
List
PgetNext () -> link-> data.link = (node
}
BOOL Remove ()
{
IF (list
{
Pget () -> data.link = (node
Return Ture;
}
Return False;
}
}
#ENDIF
[Description] Completed only the most important Insert and Remove functions and the most featured PRIOR () function, which did not re-implement. So, you use a single-link list here, I don't guarantee certain correct. Moreover, the pointer type conversion here is dependent on the compiler, and I can't affirm that other compiler can be compiled and correct. For DATAs who don't let PRIOR return to head nodes, I consider it three. Use first (); get (); such a combination can also return, so I don't care about him, so if you use prior to return NULL, it will The head node of the DATA output is coming.
[Supplement] As for the two-way circular chain list, you can also derive from this two-way linked list (in the method of derived loop linked list); or derive from the loop list (in the method of derivating the two-way linked list), it will take the same example (then doing this, I It's really troubled to vomit blood). At this point, it can be concluded that various structures of the linked list can be derived from a single-link table. In other words, the single-link table is fundamentally, if the study is a single-link table, various chain structures are not difficult.
A small test program
Void dbllisttest_int ()
{
DBLLIST
For (int i = 10; i> 1; i -) a.insert (i);
For (i = 10; i> 1; I -) cout << * a.next () << "
a.first ();
Cout << Endl;
Cout << * a.next () << endl;
Cout << * a.next () << endl;
Cout << * a.next () << endl;
Cout << * a.next () << endl;
A.Remove ();
Cout << * a.get () << Endl;
Cout << * a.prior () << Endl;
Cout << * a.prior () << Endl;
Cout << * a.prior () << Endl;
}