Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the pointer of the intermediate node of the linked list and delete the intermediate node

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report