反转c中的双向链表 [英] reverse a doubly linked list in c
本文介绍了反转c中的双向链表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为此花费适当的时间复杂度的代码
i want a proper code for this with the time complexity
推荐答案
切换一个标志,该标志指示列表是从头到尾还是从头到尾遍历的-head.
Toggle a flag that tells if the list is traversed head-to-tail or tail-to-head.
HeadToTail= !HeadToTail;
这是O(1).
不要忘记修改列表遍历例程以考虑此标志.
别开玩笑,这是可以接受的解决方案.
This is O(1).
Don''t forget to modify the list traversal routine to take this flag into account.
No kidding, this IS an acceptable solution.
这篇关于反转c中的双向链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文