Home > Back-end >  Great god help look at this way to delete list where there is a problem...
Great god help look at this way to delete list where there is a problem...

Time:10-13

Why is displayed when the input 11233 to 1233 instead of 123, and how should change?

CodePudding user response:

Delete the first while the above two sentences code, remove the first if the third sentence p=p - & gt; next

CodePudding user response:

Struct ListNode * delete (struct ListNode * head)
{
If (NULL==head) return the head;//empty table
If (NULL==head - & gt; Next) return the head;//only one element table
PFirst ListNode * and * pSecond;
PFirst=head; PSecond=head - & gt; Next;
While (pSecond) {
If (pFirst - & gt; Val==pSecond - & gt; Val) {
PFirst - & gt; Next=pSecond - & gt; Next;
Free (pSecond);
PSecond=pFirst - & gt; Next;
continue;
}
PFirst=pSecond;
PSecond=pSecond - & gt; Next;
}
return head;//no matter what the head pointer is not become
}

CodePudding user response:

In front of the code is not empty nodes ListNode list, if there is initialized once more just judgment

CodePudding user response:

reference 1st floor lirg8405 response:
delete the first while the above two lines of code, remove the first if the third sentence p=p - & gt; Next
or not, he output or 1233

CodePudding user response:

Suggested code directly ~
  • Related