打印单链表的倒退,在不断的空间和线性时间 [英] Print a singly-linked list backwards, in constant space and linear time

查看:109
本文介绍了打印单链表的倒退,在不断的空间和线性时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到一个面试问题:

打印单链表倒退,   在不断的空间和线性时间。

"Print a singly-linked list backwards, in constant space and linear time."

我的解决办法是扭转到位链表并打印这样的。难道还有其他的解决方案,无损?

My solution was to reverse the linkedlist in place and then print it like that. Is there another solution that is nondestructive?

推荐答案

如果您在打印将不再是破坏性的,因为原来的秩序恢复后再次扭转这种局面。

If you reverse it again after printing it will no longer be destructive, since the original order is restored.

这篇关于打印单链表的倒退,在不断的空间和线性时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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