//**************************************************************************
#ifndef LIST_H
#define LIST_H
//**************************************************************************
template <class Etype>
class List
{
protected:
struct Node
{
Etype Element;
Node *Next;
Node(Etype E = 0, Node *N = 0) :
Element(E), Next(N) { }
};
Node *List_Head;
Node *Current_Pos;
void Delete_List( );
public:
List( ) : List_Head ( new Node ), Current_Pos ( List_Head ) { }
virtual ~List( ) { Delete_List( ); }
inline List & operator ++ ( ) {
if ( Current_Pos != 0)
Current_Pos = Current_Pos->Next;
return *this;
}
inline int operator ! ( ) { return Current_Pos != 0; }
inline Etype & operator ( ) ( ) { return Current_Pos ?
Current_Pos->Element : List_Head->Element;}
inline int Is_Empty( ) { return List_Head->Next == 0; }
void First( ) { Current_Pos = List_Head->Next; }
virtual void Insert( Etype & X );
void reInitialize( )
{Delete_List(); List_Head = new Node; Current_Pos = List_Head;}
};
template <class Etype>
void List<Etype>::Insert( Etype & X )
{
Node *P = new Node( X, Current_Pos->Next );
if (P == 0)
cerr << "Out of Space." << endl;
else {
Current_Pos->Next = P;
Current_Pos = Current_Pos->Next;
}
}
template <class Etype>
void List<Etype>::Delete_List( )
{
Node *P, *Temp;
for (P = List_Head; P != 0; P = Temp) {
Temp = P->Next;
delete P;
}
}
//**************************************************************************
#endif // LIST_H
//**************************************************************************