# include & lt; Iostream>
using namespace std;
The template & lt; The class DataType>
Struct Node
{
DataType data;
Node
};
The template & lt; The class DataType>
The class LinkList
{
Public:
LinkList ();
LinkList (DataType a [], int n);
~ LinkList ();
Int Length ();
DataType Get (int I);
Int the Locate DataType (x);
Void Insert (int I DataType x);
DataType Delete (int I);
Void PrintList ();
Private:
Node
};
The template & lt; The class DataType>
LinkList
{
The first=new Node
First - & gt; Next=NULL;
}
/* template
LinkList
{
First - & gt; Next=NULL;
for(int i=0; I
Node
S - & gt; data=https://bbs.csdn.net/topics/a [I];
S - & gt; Next=first - & gt; Next;
First - & gt; Next=s;
}
} */
Template
LinkList
{
First - & gt; Next=NULL;
Node
for(int i=0; I
Node
S - & gt; data=https://bbs.csdn.net/topics/a [I];
R - & gt; Next=s;
R=s;
}
R - & gt; Next=NULL;
}
Template
Int LinkList
{Node
Int Count=0;
while(p!=NULL)
{p=p - & gt; Next;
Count++;
}
Return the Count.
}
Template
DataType LinkList
{Node
Int Count=1;
while(p!=NULL& & Count{
P=p - & gt; Next;
Count++;
}
If (p==NULL) throw "location";
The else
The return p - & gt; The data;
}
Template
Int LinkList
{int Count=1;
Node
while(p!=NULL)
{
If (p - & gt; data=https://bbs.csdn.net/topics/=x) return the Count;
P=p - & gt; Next;
Count++;
}
Return 0;
}
Template
Void LinkList
{
Node
Int Count=0;
while(p!=NULL& & Count{
P=p - & gt; Next;
Count++;
}
If (p==NULL)
Abnormal "throw" insert position;
The else
{
Node
S - & gt; data=https://bbs.csdn.net/topics/x;
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
}
}
Template
DataType LinkList
{
Node
Int Count=1;
while(p!=NULL& & Count{
P=p - & gt; Next;
Count++;
}
If (p==NULL | | p.n ext==NULL)
Cout<" Position error ";
The else
{Node
Int x=q - & gt; The data;
P - & gt; Next=q - & gt; Next;
The delete q;
Return the x;
}
}
Template
Void LinkList
{
Node
while(p!=NULL)
{
P=p - & gt; Next;
Cout}
}
Template
LinkList
{Node
While (first!=NULL)
{
Q=first;
The first=first - & gt; Next;
The delete q;
}
}
Int main ()
{
,2,5,8,5 int a [5]={1}, b [5]=,5,9,7,6 {2};
LinkList
LinkList
List_1. PrintList ();
Return 0;
}
CodePudding user response:
LinkListThere is no to the first assignment in the function
template
LinkList: : LinkList (DataType a [], int n)//head interpolation
{first=new Node;
First - & gt; data=https://bbs.csdn.net/topics/a [0].
Node* r=first;
for(int i=1; I{Node * s=new Node ;
S - & gt; data=https://bbs.csdn.net/topics/a [I];
R - & gt; Next=s; R=s;
}
R - & gt; Next=NULL;
}