如何在c中找到单链表的中间节点 [英] How to find middle node of singly linked list in c

查看:101
本文介绍了如何在c中找到单链表的中间节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我有一个问题PLZ帮助我。我的问题是......

如何在单次遍历中找到链表的中间节点???????

hi friends, i have a question plz help me. my question is ...
how can i find middle node of linked list in single traverse???????

推荐答案


嗨朋友们,我有一个问题PLZ帮助我。我的问题是......

如何在单次遍历中找到链表的中间节点???????
hi friends, i have a question plz help me. my question is ...
how can i find middle node of linked list in single traverse???????



每次都要遍历递增计数器的整个链表。然后使用该计数器,您将确切知道中间位置(假设在第一次通过它和检查中间位置之间没有插入节点)

Go through the entire linked list incrementing a counter each time. Then with that counter you''ll know exactly where the middle is (assuming no nodes have been inserted between the first time you go through it and when you check for the middle)


I'迭代,计算每个节点,然后计算一半。
I''d iterate through, count each node, and then half that count.



我会迭代,计算每个节点,并且然后一半计算。
I''d iterate through, count each node, and then half that count.



甜蜜!最后击败了一个mod。

Sweet! Finally beat a mod to it.


这篇关于如何在c中找到单链表的中间节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆