Home > Back-end >  About singly linked lists inversion problem about incoming parameters change
About singly linked lists inversion problem about incoming parameters change

Time:09-18

/Reverse/List (List 1)
//{
//
//the List s, p, TMP, rear;
//p=(List) malloc sizeof (struct Node)); p-> Next=NULL;
//rear=p;
//while (L)
//{
//s=(List) malloc sizeof (struct Node));
//s - & gt; Data=https://bbs.csdn.net/topics/L-> Data;
//s - & gt; Next=rear - & gt; Next;
//rear - & gt; Next=s;
//L=L - & gt; Next;
//}
//TMP=p; P=p - & gt; Next; Free (TMP);
//return p;
//}
The List Reverse (List L) {
List the rs=NULL;
While (L) {
The List of p=L;
L=L - & gt; Next;
p-> Next=rs;
Rs=p;
}
return rs;
}
Reverse the two incoming parameters List why the execution of the above L L didn't change the following L

CodePudding user response:

To List the Reverse (List& L);
You pass in a pointer variable, for L modifications are changed to a temporary variable, so you need to pass the reference,
  • Related