如何通过链表进行斐波那契(不是通过递归) [英] How to do fibonacci by linked list ( not by recursive)
问题描述
因为在链表中每个节点只包含一个数字,如
curr-> nodevalue_1 = 0
curr-> nodevalue_2 = 1
sum-> nodevalue = curr-> nodevalue_1 + curr-> nodevalue_2
所以当数字达到> 10或> 100时链接列表需要另一个
节点(我可以将节点添加到前面)但是怎么做呢?
ex:89 + 144 = 233
如何将它添加到总和链表?
请帮忙(记住不是递归问题)
" fighterman19" <音响********** @ comcast.net>写了...因为在链表中每个节点只包含一个数字,如
这是一个要求还是只是你对链表的理解?
curr-> nodevalue_1 = 0
curr-> nodevalue_2 = 1
sum-> nodevalue = curr-> nodevalue_1 + curr-> nodevalue_2
所以当数字上升到> 10或> 100并且链表需要另一个节点时(我可以将节点添加到前面)但是怎么做呢?
ex:89 + 144 = 233
如何将它添加到总和链表?
请帮忙(记住不是递归问题)
有什么问题?你不能用结转来实现添加吗?
0 =>随身携带。
label_1:
next_digit1 + next_digit2 + carry =>结果。
如果结果> 9然后
1 =>随身携带。
结果 - 10 =>结果。
其他
0 =>结账。
结束 - 如果
商店结果
如果have_more_digits转到label_1
我不要这里看不到C ++语言问题,BTW。
Victor
fighterman19写道:
因为在链表中每个节点只包含一个数字,如
curr-> nodevalue_1 = 0
curr-> nodevalue_2 = 1
sum-> nodevalue = curr-> nodevalue_1 + curr-> nodevalue_2
所以当数字达到> 10或> 100且链表需要另一个节点时(我可以添加节点到前面)但怎么办呢?
ex:89 + 144 = 233
如何将它添加到总和链表?
请帮忙(记住不是递归问题)
为什么你会为此使用链表呢?你的问题不是很有意义。
-Kevin
-
我的电子邮件地址有效,但会定期更改。
要联系我,请使用最近发布的地址。
fighterman19写道:因为在链表中每个节点只包含一个数字,如
curr-> nodevalue_1 = 0
curr-> nodevalue_2 = 1
sum-> nodevalue = curr-> nodevalue_1 + curr-> nodevalue_2
所以当数字达到> 10或> 100且链表需要另一个
时节点(我可以将节点添加到前面)但是怎么做呢?
ex:89 + 144 = 233
如何将它添加到总和链表?
我建议你做一个自己的功课,然后
发布你的代码,而不是要求我们为你做这个?
because in linked list each node contains only one digit like
curr->nodevalue_1= 0
curr->nodevalue_2=1
sum->nodevalue = curr->nodevalue_1 + curr->nodevalue_2
so when the number go up to >10 or >100 and the linked list need another
node (I can add the node to the front ) but how can do the sum ?
ex: 89+144 = 233
how can I add it to the sum linked list?
please help ( remember not a recursive problem)
解决方案"fighterman19" <fi**********@comcast.net> wrote...because in linked list each node contains only one digit like
Is that a requirement or just your understanding of linked lists?
curr->nodevalue_1= 0
curr->nodevalue_2=1
sum->nodevalue = curr->nodevalue_1 + curr->nodevalue_2
so when the number go up to >10 or >100 and the linked list need another
node (I can add the node to the front ) but how can do the sum ?
ex: 89+144 = 233
how can I add it to the sum linked list?
please help ( remember not a recursive problem)
What''s the problem? Can''t you implement addition with carry-over?
0 => carry.
label_1:
next_digit1 + next_digit2 + carry => result.
if result > 9 then
1 => carry.
result - 10 => result.
else
0 => carry.
end-if
store result
if have_more_digits go to label_1
I don''t see C++ language issue here, BTW.
Victor
fighterman19 wrote:
because in linked list each node contains only one digit like
curr->nodevalue_1= 0
curr->nodevalue_2=1
sum->nodevalue = curr->nodevalue_1 + curr->nodevalue_2
so when the number go up to >10 or >100 and the linked list need another
node (I can add the node to the front ) but how can do the sum ?
ex: 89+144 = 233
how can I add it to the sum linked list?
please help ( remember not a recursive problem)
Why on earth would you use a linked list for this? Your question doesn''t
make much sense.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
fighterman19 wrote:because in linked list each node contains only one digit like
curr->nodevalue_1= 0
curr->nodevalue_2=1
sum->nodevalue = curr->nodevalue_1 + curr->nodevalue_2
so when the number go up to >10 or >100 and the linked list need another
node (I can add the node to the front ) but how can do the sum ?
ex: 89+144 = 233
how can I add it to the sum linked list?
please help ( remember not a recursive problem)
May I suggest that you take a stab at doing your own homework, and then
post your code, instead of asking us to do it for you?
这篇关于如何通过链表进行斐波那契(不是通过递归)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!