CodePudding user response:
For example
Void Insert (List * L, Node e) {//here is what the secondary pointer? Normally use the List L is ok, because the List is in itself a pointer type, is a linked List is empty, the new List?
If (* L==NULL) {
* L=(List) malloc (sizeof (Node));
Strcpy (* L - & gt; ID, e.i d);
* L - & gt; Score=e.S core;
* L - & gt; Next=NULL;
return;
}
The List of p=* L;
While (p - & gt; Next!=NULL) {
P=p - & gt; Next;
}
p-> Next=(List) malloc (sizeof (Node));
Strcpy (p - & gt; Next - & gt; ID, e.I D);
p-> Next - & gt; Score=e.S core;
p-> Next - & gt; Next=NULL;
}
Void Swap (List * L, int, int j) {//should be here with the List L is ok, don't need the secondary pointer
Int CNT=0;
The List of p=* List, pi1=p, pi2=NULL, pj1=p, pj2=NULL, TMP;
While (p!=NULL) {
If (CNT==I - 1) pi1=p;//I on a node
If (CNT==I) pi2=p;//I node
If (CNT==j - 1) pj1=p;//j in a node
If (CNT==j) pj2=p;//j node
cnt++;
P=p - & gt; Next;
}
If (pi2!=NULL & amp; & Pj2!=NULL & amp; & Pi2!=pj2) {//if found the two nodes, and the two nodes is different, the exchange of node
Pi1 - & gt; Next=pj2;//I on a node's next point j node
Pj1 - & gt; Next=pi2;//j a node on the next point I node
TMP=pj2 - & gt; Next;
Pj2 - & gt; Next=pj1 - & gt; Next; The next point to the original I//j node next
Pi2 - & gt; Next=TMP;//I node next next to the original j node
}
}
CodePudding user response:
Thank you ah, just began to self-study, difficult to operate