# Include "stdafx. h"
# Include <iostream>
Using namespace std;
Template <typename T>
Struct Node
{
T value;
Node * next;
Node * pre;
};
Template <typename T>
Class List
{
Private:
Node <T> * head;
Node <T> * current;
Node <T> * create;
Int number;
Public:
List ()
{
Head = new Node <T> ();
Head-> next = NULL;
Head-> pre = NULL;
Current = head;
Number = 0;
}
~ List (){
Node <T> * temp = current;
While (temp-> next! = NULL)
{
Temp = temp-> next;
Delete (temp-> pre );
}
If (temp-> next = NULL)
{
Delete (temp );
}
Cout <"" "<endl;
}
Void Add (T)
{
Create = new Node <T> ();
Create-> value =;
Create-> next = current;
Create-> pre = NULL;
Current-> pre = create;
Current = create;
Number ++;
}
Bool Contains (T ){
Node <T> * temp = current;
Bool ret = false;
While (temp-> next! = NULL)
{
If (temp-> value =)
{
Ret = true;
Break;
}
Temp = temp-> next;
}
Return ret;
}
Void Remove (T ){
Node <T> * temp = current;
While (temp-> next! = NULL)
{
If (temp-> value =)
{
Number --;
If (temp-> pre! = NULL)
{
Temp-> pre-> next = temp-> next;
Temp-> next-> pre = temp-> pre;
Delete (temp );
}
Else
{
Current = current-> next;
Delete (temp );
}
Break;
}
Else
{
Temp = temp-> next;
}
}
}
Void Display ()
{
Node <T> * temp = current;
While (temp-> next! = NULL)
{
Cout <temp-> value <endl;
Temp = temp-> next;
}
}
Int getNumber (){
Return number;
}
};
Void Test ()
{
List <int> * p = new List <int> ();
For (int I = 0; I <3553; I ++)
{P-> Add (I );
}
P-> Display ();
Cout <"number:" <p-> getNumber () <endl;
Getchar ();
Cout <p-> Contains (333) <endl;
Delete (p );
}
Int main ()
{
Test ();
Getchar ();
Return 0;
}