反转单个链表 [英] reverse a single linked list
问题描述
大家好,
我想在没有使用很多
变量的情况下实际反转单个链表,我有一个递归解决方案,但我想要一个迭代的。
有人可以帮我吗?
Hi Everyone,
I want to actually reverse a single linked list without using many
variables, i have a recurssive solution, but i wanted an iterative one.
can anyone help me on this?
推荐答案
sa ***** @ yahoo.co.in 写道:
大家好,
我想在没有使用很多
变量的情况下实际反转单个链表,我有一个递归解决方案,但我想要一个迭代的解决方案。
Hi Everyone,
I want to actually reverse a single linked list without using many
variables, i have a recurssive solution, but i wanted an iterative one.
为什么你想要那个,你的递归解决方案还不够好?
-
:wq
^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C
Why would you want that, is your recursive solution not good enough ?
--
:wq
^X^Cy^K^X^C^C^C^C
>
你为什么要这样,你的递归解决方案还不够好?
>
Why would you want that, is your recursive solution not good enough ?
是的,递归解决方案是好但是使用了大量的堆栈空间并且它在堆栈空间有限的环境中可能没什么用,例如嵌入式系统通常不鼓励递归函数。
Yes, recursive solution is good but uses a lot of stack space and it
might not be helpful in a envirnoment where stack space is limited like
embedded systems where recursive functions are normally not encouraged.
sa*****@yahoo.co。在写道:
>
>
>>
为什么你想要那个,你的递归解决方案还不够好?
>>
Why would you want that, is your recursive solution not good enough ?
是的,递归解决方案很好但是使用了大量的堆栈空间而且它在一个环境中可能没什么用处,其中堆栈空间有限,例如嵌入式系统通常不鼓励递归函数。
Yes, recursive solution is good but uses a lot of stack space and it
might not be helpful in a envirnoment where stack space is limited like
embedded systems where recursive functions are normally not encouraged.
然后使用双向链表。
-
:wq
^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C
Use a doubly linked list then.
-
:wq
^X^Cy^K^X^C^C^C^C
这篇关于反转单个链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!