Home > Back-end >  Just learning, have a big help to see where is there a problem? To delete duplicate nodes in the sin
Just learning, have a big help to see where is there a problem? To delete duplicate nodes in the sin

Time:10-02

#include
using namespace std;
The template & lt; The class DataType>
Struct Node
{
DataType data;
Node * next;
};
The template & lt; The class DataType>
The class LinkList
{
Public:
Void DeleteSame ();
Void PrintList ();
Private:
Node * first;
The template & lt; The class DataType>
Void LinkList : : PrintList ()
{
Node * p=first - & gt; Next;
While (p!=NULL)
{
Cout & lt;

P=p - & gt; Next;
}
Cout & lt; }
The template & lt; The class DataType>
Void Linklist : : DeleteSame ()
{
Node * p * q * s;
P=first - & gt; Next;
For (p; p!=NULL; P=p - & gt; Next)
{
S=p;
For (q=p - & gt; Next; q!=NULL; )
{
If (q - & gt; data=https://bbs.csdn.net/topics/=p-> data)
{
S - & gt; Next=q - & gt; Next;
The delete q;
Q=s - & gt; Next;
}
The else
{
S=q;
Q=q - & gt; Next;
}
}
}
}
Int main () {
Int r [6]=,2,3,4,5,3 {1};
LinkList L (r, 6);
cout<& lt;" The original data is: ";
L.P rintList ();
L.D eleteSame ();
cout<& lt;" Delete the data of the: ";
L.P rintList ();
return 0;
}

  • Related