Singly linked list - OJ

Topic: Remove Linked List Elements-203

 answer:

First of all, we first define two pointers prev and cur

Cur function: It is used to compare the val in cur with the val to be deleted. If they are equal, the structure currently pointed to by cur will be freed

Prev function: prevent cur from finding the next data of the linked list after free drops the structure pointed to by cur

Note: If the data in the linked list is to be deleted, it is equivalent to deleting the head every time, and we have to deal with it specially

 Code:

Guess you like

Origin blog.csdn.net/qq_58286439/article/details/130209094