打印一个简单的链表向后没有递归,在两次传球最多,使用恒定的额外的内存,留下完好无损 [英] Print a simply linked list backwards with no recursion, in two passes at most, using constant extra memory, leaving it intact

查看:167
本文介绍了打印一个简单的链表向后没有递归,在两次传球最多,使用恒定的额外的内存,留下完好无损的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您必须打印一个简单的链表向后:

You must print a simply linked list backwards:

  • 无递归
  • 随着不断的额外内存
  • 在线性时间
  • 离开列表完整
  • 后加入两次传球最多
  • Without recursion
  • With constant extra memory
  • In linear time
  • Leaving the list intact
  • Added Later Two passes at most

推荐答案

大厦锐齿的回答,您可以将打印和第二反转在同一个通行证。

Building on sharptooth's reply, you can combine the printing and second inversion in the same pass.

编辑:在从单线程视图列表保持不变,因为后置条件等于pre-条件

The "list is left intact" from a single-threaded view because the post-condition equals the pre-condition.

编辑2:不知道我是如何得到的答案,但我会接受它,因为我已经打了代表上限的一天。我给了锐齿+1了。

Edit 2: Not sure how I got the answer, but I'll take it since I've hit the rep cap for the day. I gave sharptooth a +1 too.

这篇关于打印一个简单的链表向后没有递归,在两次传球最多,使用恒定的额外的内存,留下完好无损的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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