473,804 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do fibonacci by linked list ( not by recursive)

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)

Jul 19 '05 #1
11 6371
"fighterman 19" <fi**********@c omcast.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_digit s go to label_1

I don't see C++ language issue here, BTW.

Victor
Jul 19 '05 #2
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.

Jul 19 '05 #3
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?

Jul 19 '05 #4
Where the hell in my post that you see I YOU or other people to do my
homework for me?

I just want to know how to handle this logic. Did I ask for the entire
program?
and if YOU can't do it (or whatsoever that make you think you are good and
whoever ask in this group is stupid) so SHUT YOUR FUCKING MOUTH UP

if all the members in this group are like YOU, this group is not gonna exist
because noone will ask any questions.

by the way "THANK SO MUCH" even YOU are not helpful

"red floyd" <no*****@here.d ude> wrote in message
news:%E******** **********@news svr27.news.prod igy.com...
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?

Jul 19 '05 #5
!!!!!!!!!!!.... .......???

Sorry is it C++?
I have no idea what it is. May be I have not learned this one yet. Is there
anyway to do with linked list?

"Victor Bazarov" <v.********@att Abi.com> wrote in message
news:dp76b.3680 85$o%2.165927@s ccrnsc02...
"fighterman 19" <fi**********@c omcast.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_digit s go to label_1

I don't see C++ language issue here, BTW.

Victor

Jul 19 '05 #6
Yes, I know it doesn't not make sence because the best way to do fibonacci
is to use recursive, right?
But because I am learning about linked list so my task is to use linked list
to do fibonacci.
That's why I don't know how to handle the logic when the number has too many
digit.

by the way do you understand what i'am asking? I know it is hard to explain
w/o the picture.

"Kevin Goodsell" <us************ *********@never box.com> wrote in message
news:Ht******** *******@newsrea d3.news.pas.ear thlink.net...
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.

Jul 19 '05 #7
> Yes, I know it doesn't not make sence because the best way to do fibonacci
is to use recursive, right?


If you by this meant something like
int fib(int n) { return n < 2 ? 1 : fib(n-1) + fib(n-2); }
then wrong.

It turns out counting the numbers in the opposite order is
(significantly) more efficient, since you will notice that this
solution would calculate small fibonacci number very many times if n
would be greater than very small.

Best regards
Michael Stockman
d0*****@nada.kt h.se

Jul 19 '05 #8
fighterman19 wrote:

Please do not top-post. Re-read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/
Yes, I know it doesn't not make sence because the best way to do fibonacci
is to use recursive, right?
Definitely not. Recursive fibonacci is terribly inefficient, because it
does the same calculations over and over.
But because I am learning about linked list so my task is to use linked list
to do fibonacci.
That's why I don't know how to handle the logic when the number has too many
digit.
I don't know what the number of digits has to do with it.

by the way do you understand what i'am asking? I know it is hard to explain
w/o the picture.


No, I don't understand.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #9
"fighterman 19" <fi**********@c omcast.net> wrote in message
news:rt******** ************@co mcast.com...
<snip faintly ridiculous flame>

Wow, you can swear at someone in a newsgroup. We'd all be very impressed, if
it wasn't quite so stunningly lame. And to think I was actually about to
help you and had written working code for you (assuming I understood your
question correctly, it wasn't hugely clear). For the record, you'd be
surprised at how many people post here expecting someone to do their
homework. The result of which is, of course, that we prefer to answer
questions where people have actually had a stab at the code themselves; it
demonstrates a modicum of effort. Of course, if we're in a good mood and
feeling kind (which is most of the time, in my experience), we'll try and
help out anyway, even if we're not given a huge amount to go on. At any
rate, we will until you decide to start yelling at people, at which stage
most of us generally decide it's not worth the bother and just killfile you.
FWIW, if you apologise in the immediate future (i.e. preferably before
everybody's read the original post), I think people would still try and
answer your question. I suspect you're hovering dangerously close to the
edge of quite a few people's killfiles, though. And the only person who
loses out if everyone ignores you is you, bottom line. Perhaps a damage
limitation exercise is in order?

Just a suggestion,

Stuart.

P.S. The site you're looking for is http://www.parashift.com/c++-faq-lite/
Perhaps reading Section 5 would be useful?

<snip>
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
13578
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e., head and tail are not connected. Of course, recursive function aproach to traverse the list is one way. But, depending upon the list size, it could overrun the stack pretty fast.
33
1837
by: junky_fellow | last post by:
Consider a singly-linked list. Each node has a structure, struct node { char c; struct node *next; }; Each of the nodes contain an alphabetic character. Can anybody suggest a way to print the characters in reverse order.
4
3602
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL using the recursive call how to change the last node pointer to head and head->next to null without using the extra global pointer Mayur
1
10656
by: PhilB | last post by:
I have been having issues trying to merge sort a double linked list. (I would supply the code, but it is locked away on an inaccessable computer.) The list always results in an unsorted list, but no errors. I think I have tracked it down to the recursive functions locking on a node and then the node being moved during the sorting process. I used an example which sorts an array, so I had to make some guesses on interfacing it with a...
22
8050
by: joshc | last post by:
In an interview for an embedded software position recently I was asked to write code, in C, for printing the contents of a linked list backwards. After a few minutes I came up with the recursive solution. Being that recursion is frowned upon in embedded software, the answer was not what the interviewer expected, but alas it was correct. I asked some friends how they would have answered and another answer is to reverse the list and then...
11
8718
by: sam_cit | last post by:
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?
0
8639
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be anything from a short integer value to a complex struct type, also has a pointer to the next node in the single-linked list. That pointer will be NULL if the end of the single-linked list is encountered. The single-linked list travels only one...
6
1595
by: Hamster | last post by:
Hi, Need help with my code on reversing a singly linked list, here's my code: void reverseList ( List& listObj) { ListNode*pHeadnew=listObj.lastPtr, *pTailnew=listObj.firstPtr;
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.