How to set the pointer of the intermediate node of the linked list and delete the intermediate node
This article mainly explains "how to set the pointer of the middle node of the linked list and delete the middle node". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn how to give the pointer to the middle node of the linked list and delete the middle node.
The questions are as follows
Input: pointer to node c in linked list a-> b-> c-> d-> e
Output: no return value, but the new linked list becomes a-> b-> d-> e
Answer:
I didn't figure it out for a long time. I didn't know the solution until I read the hint. A little trick is used here. To delete the intermediate node, but we do not know to delete the last node p of the node, so we cannot delete the node by modifying the pointer (p-> next=del- > next), but we know that we want to delete the latter node of the node, so we change our way of thinking, exchange the data of the node to be deleted with the data of the latter node of the node, and then delete the latter node to achieve our goal. But this method cannot delete the last node for obvious reasons.
The code is as follows:
/ / a tricky solution,can't delete the last one element
Int delete_node (NODE* node) {
Int data
NODE * pendant node-> next
Node- > data=p- > data
Node- > next=p- > next
Free (p)
}
Thank you for your reading. The above is the content of "how to set the pointer of the intermediate node of the linked list and delete the intermediate node". After the study of this article, I believe you have a deeper understanding of how to set the pointer of the intermediate node of the linked list. delete the intermediate node of this problem has a deeper understanding, the specific use of the need for practice to verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!