The member function unique () can ensure that two consecutive objects in the linked list container are unique. That is, the element values of any consecutive objects in the linked list container must be different, however, the uniqueness of all objects in the linked list container cannot be guaranteed. Example:
Std;
_ Tmain (argc, _ TCHAR * argv [])
{
List <> c1;
> Mypred;
C1.push _ back (-10 );
C1.push _ back (10 );
C1.push _ back (10 );
C1.push _ back (20 );
C1.push _ back (20 );
C1.push _ back (-10 );
Cout <endl;
Copy (c1.begin (), c1.end (), ostream_iterator <> (cout ,));
Cout <endl;
List <> c2 = c1;
;
Cout <endl;
Copy (c2.begin (), c2.end (), ostream_iterator <> (cout ,));
Cout <endl;
List <> c3 = c2;
; The first element of the linked list has different object elements.
Cout <endl;
Copy (c3.begin (), c3.end (), ostream_iterator <> (cout ,));
Cout <endl;
0;
}
Execution result: