Home > Back-end >  The great god please answer?????????
The great god please answer?????????

Time:09-28

# include & lt; Iostream>
# include & lt; String. H>
Using namespace STD.

//Definition of the data element
Struct NBAplayer {
Char name [20].
int height;
int age;
Int Threept;
Int dunk.
Int block;
Int overall;

};

//the Node
The template & lt; The class T>
Struct Node {
T data;//data field
Node * next;//A pointer which points to A node
};

//the class declaration
The template & lt; The class T>
The class LinkedList {
Public:
LinkedList ();//None - parameter constructor
LinkedList (T a [], int n);//Constructor.
~ LinkedList () {}//Destructor.
Int Length ();//Return the length of the list
Void the Get (int I);//Search by position
Int the Locate (T, x);//Search by player
Void Insert (int I, T, x);//insert player x to the position I
Void the Delete (int I);//delete the ith player
Void PrintList ();//the output
Private:
Node * first;
};

//the Following are the functions provides of the class
The template & lt; The class T>
LinkedList : : LinkedList () {//implementation of none - parameter constructor
The first=new Node;
First - & gt; Next=NULL;
}

The template & lt; The class T>
LinkedList : : LinkedList (T a [], int n) {//implementation of constructor
int i;
Node * s;
The first=new Node;
//first - & gt; Next=NULL;
for(i=0; iS=new node;
S - & gt; data=https://bbs.csdn.net/topics/a [I];
S - & gt; Next=first - & gt; Next;
First - & gt; Next=s;
}
}
//
The template & lt; The class T>
Int LinkedList : : Length () {//implementation of Length ()
S=first - & gt; Next; int count=0;
while(p! NULL)
{
P=p - & gt; Next;
count++;
}
return count;
/*
Return length;

*/
}

The template & lt; The class T>
Void LinkedList : : Get (int I) {//implementation of the Get (), search by the position
S=first - & gt; Next; Int count=1;
While (S! NULL& & Count{
S=S - & gt; Next;
count++;
}
If (S==NULL) throw "weizhifeifa";
The else
Cout & lt; Data [I - 1]. The name & lt; <"' & lt; Data [I - 1]. Height & lt; <"' & lt; Data [I - 1]. The age
Data [I - 1]. Three_pt & lt; Data [I - 1]. Dunk & lt; Data [I - 1]. Block & lt; Data [I - 1]. Overall/*

If (I & lt; 1 & amp; & I & gt; Length) throw "illegal" find position;
//cout "" means the print
Cout & lt; Data [I - 1]. The name & lt; <"' & lt; Data [I - 1]. Height & lt; <"' & lt; Data [I - 1]. The age
Data [I - 1]. Three_pt & lt; Data [I - 1]. Dunk & lt; Data [I - 1]. Block & lt; Data [I - 1]. Overall//the output the details of the player. "endl" means end the line
*/
}
The template & lt; The class T>
Int LinkedList : : Locate (NBAplayer x) {//implementation of the Locate (), search by the position
S=first - & gt; Next; Int count=1;
While (S! NULL) {
If (STRCMP (S - & gt; Data [I]. Name, x.n ame)==0) {
//"STRCMP is" means "string compare". If two strings are the same, the function returns 0;
return i+1;
}
}
return 0;
}
The template & lt; The class T>
Void LinkedList : : Insert (int I NBAplayer x) {//implementation of the Insert ()

S=first; int count=0;
While (S! NULL& & Count{
S=S - & gt; Next;
count++;
}
If (S==NULL) threw "weizhifeifa";
The else {
P=new Node; P - & gt; The DATE=x;
P - & gt; Next=S - & gt; Next;
S-> Next=p;
}
}
The template & lt; The class T>
NBAplayer LinkedList : : Delete (int I) {//implementation of the Delete ()
S=first; int count=0;
While (S! NULL& & Count{
S=S - & gt; Next;
count++;
}
If (S==NULL | | S - & gt; Next==NULL)
Throw "weizhifeifa";
The else
P=s - & gt; Next; X=p - & gt; data;
S-> Next=p - & gt; Next;
The delete p;
//return x;
}
The template & lt; The class T>
Void LinkedList : : PrintList () {//implementation of PrintList ()
S=first - & gt; Next;
While (S! NULL) {
Cout & lt; Data [I - 1]. The name & lt; <"' & lt; Data [I - 1]. Height & lt; <"' & lt; Data [I - 1]. The age
<"' & lt; Data [I - 1]. Threept & lt; <"' & lt; Data [I - 1]. Dunk<"' & lt; Data [I - 1]. Block & lt; <'
Data [I - 1]. OverallS=S - & gt; Next;
}
}
//Above is the complete class

//the main function
Int main () {
NBAplayer X;
Int I, j;
//First, we define three players, and put them in an array
NBAplayer player [3]={
{2.03, "James", 31,60,99,90,95},
{" Harden ", 1.96, 26,80,89,75,90},
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related