# include
Template
The class List {
Struct Node/statement/two-way nodes
{
T data;
Prev Node * and * next;
The Node (const T& D=(T), Node * p=NULL, Node * n=NULL) : the data (d), prev (p), next (n) {}
};
Node * head;//head node pointer
Node * tail;//end node pointer
Int size;//data node number
Void Init ()//initialization function
{
Size=0; The head=new Node; Tail=new Node; The head - & gt; Next=tail; Tail - & gt; Prev=head;
}
Public:
The class const_iterator {
Protected:
The current Node *;
T& Retrieve const () {return current - & gt; The data; }
Const_iterator (Node * p) : the current (p) {}//conversion constructors
Friend class List
Public:
Const_iterator () : the current (NULL) {}
Const T& Const operator * () {return retrieve (); }//return current - & gt; The data;
Const_iterator & amp; Before operator++ ()//+ +
{
The current=current - & gt; Next;
Return * this;
}
After const_iterator operator++ (int)//+ +
{
Const_iterator old=* this;//old=current;
+ + (* this);//the current=current - & gt; Next;
Return old;
}
Const_iterator & amp; Operator - before ()//-
{
The current=current - & gt; Prev.
Return * this;
}
Const_iterator operator - (int)//post -
{
Const_iterator old=* this;//old=current;
- (* this);//the current=current - & gt; Next;
Return old;
}
Boolean operator==(const const_iterator * RHS) const
{
Return the current==RHS. Current;
}
Boolean operator!=(const const_iterator & amp; RHS) const
{
Return the current!=RHS. Current;
}
};
The class iterator: public const_iterator
{
Protected:
The current Node *;
T& Retrieve const () {return current - & gt; The data; }
The iterator (Node * p) : const_iterator (p) {}
Friend class List
Public:
The iterator () {}
T& The operator * () {return retrieve (); }
Const T& Const operator * () {return const_iterator: : operator * (); }
Iterator& Before operator++ ()//+ +
{
The current=current - & gt; Next;
Return * this;
}
After the iterator operator++ (int)//+ +
{
The iterator old=* this;//old=current;
+ + (* this);//the current=current - & gt; Next;
Return old;
}
Iterator& Operator - before ()//-
{
The current=current - & gt; Prev.
Return * this;
}
The iterator operator - (int)//post -
{
The iterator old=* this//old=current;
- (* this);//the current=current - & gt; Next;
Return old;
}
};
The List () {Init (); }//the default constructor, the empty table
The List (const List
To the List () {the Clear (); Delete the head; Delete the tail; }//destructors
Const List& Operator=(const List& L);//copy assignment operator function
Iterator the Begin () {return iterator (head - & gt; Next); }
Const const_iterator the Begin () {return const_iterator (head - & gt; Next); }
The iterator End () {return iterator (tail); }
Const const_iterator End () {return const_iterator (tail); }
T& The Front () {return * the Begin (); }//return the first element of reference
Const T& Front const () {return * the Begin (); }//returns the first element type constant reference
T& The Back () {return * - End (); }//returns the tail element reference
Const T& Const Back () {return * - End (); }//returns the tail element type constant reference
Void Push_front (const T& Item) {Insert (the Begin (), the item). }//first insert
Void Push_back (const T& Item) {Insert (End (), the item); }//tail
Void Pop_front () {Erase (the Begin ()); }//delete data in the first node
Void Pop_back () {Erase (End ()); }//delete data end node
The iterator Erase (iterator itr);//remove indicator position on the node
The iterator Insert (iterator itr, const T& Item);//in indicator position insert item
Const int Size () {return the Size; }//get data node number
Const bool Empty () {return size==0; }//to empty function
Void the Clear () {while (! The Empty ()) Pop_front (); }//clear the table, the result is empty table
};
Template
Const List
The Clear ();//clear empty table
For (const_iterator itr=l.B do v.begin (); Itr!=l.E nd (); + + itr)//copy table l node individually
Push_back (* itr);
Return * this;
}
Template
Typename List
List
{
Node * p=itr. Current;
The iterator re (p - & gt; Next);
P - & gt; Prev - & gt; Next=p - & gt; Next;
P - & gt; Next - & gt; Prev=p - & gt; Prev.
The delete p;
Size -;
Return re;
}
Template
Typename List
List
{
Node * p=itr. Current;
p - & gt; Prev - & gt; Next=new Node (item, p - & gt; Prev, p);
P - & gt; Prev=p - & gt; Prev - & gt; Next;
Size++;
Return the iterator (p - & gt; Prev);
}
Point out that it is the red to the location of the place,,, for bosses
CodePudding user response:
Uninitialized p - & gt; prevCodePudding user response:
The