Monday, July 9, 2007

Write code to add two polynomials.

Here is some pseudocode


mynode *polynomial_add(mynode *h1, mynode *h2, mynode *h3)
{
mynode *p1, *p2;
int x1, x2, y1, y2, cf1, cf2, cf;

p1 = h1->next;

while(p1!=h1)
{
x1 = p1->px;
y1 = p1->py;
cf1 = p1->cf;

// Search for this term in the second polynomial

p2 = h2->next;

while(p2 != h2)
{
x2 = p2->px;
y2 = p2->py;
cf2 = p2->cf;

if(x1 == x2 && y1 == y2)break;

p2 = p2->next;

}


if(p2 != h2)
{
// We found something in the second polynomial.

cf = cf1 + cf2;
p2->flag = 1;

if(cf!=0){h3=addNode(cf,x1,y1,h3);}
}
else
{
h3=addNode(cf,x1,y1,h3);
}

p1 = p1->next;

}//while


// Add the remaining elements of the second polynomail to the result

while(p2 != h2)
{
if(p2 -> flag ==0)
{
h3=addNode(p2->cf, p2->px, p2->py, h3);
}
p2=p2->next;
}

return(h3);
}

25 comments:

  1. My spouse and I stumbled over here from a
    different web page and thought I may as well check things out.
    I like what I see so i am just following you. Look forward to looking
    at your web page yet again.
    My page :: android tablet pc

    ReplyDelete
  2. An interesting discussion is worth comment. I think that you
    should write more about this issue, it may not be a taboo subject
    but usually people don't discuss these subjects. To the next! Kind regards!!
    my webpage: Western Australia

    ReplyDelete
  3. Having read this I believed it was extremely enlightening.

    I appreciate you taking the time and energy to put this informative
    article together. I once again find myself personally spending a significant amount of time both
    reading and posting comments. But so what, it was still worthwhile!
    Take a look at my blog post : cheap iPhone 5 for sale online

    ReplyDelete
  4. Hello There. I found your blog the use of msn. This is a
    very neatly written article. I'll be sure to bookmark it and return to read more of your helpful info. Thank you for the post. I will definitely return.
    my webpage: Photography Special Effects

    ReplyDelete
  5. I will immediately grasp your rss feed as I can't to find your e-mail subscription link or e-newsletter service. Do you've any?
    Kindly permit me understand in order that I may subscribe.
    Thanks.
    my page > Trick Photography and Special Effects

    ReplyDelete
  6. When someone writes an post he/she retains the plan of a user in
    his/her brain that how a user can be aware of it.
    Therefore that's why this article is perfect. Thanks!
    Here is my website :: penilarge najtaniej

    ReplyDelete
  7. We are a group of volunteers and starting a new scheme in our community.
    Your site provided us with valuable info to work on.
    You've done an impressive job and our entire community will be grateful to you.
    My weblog - search engine optimization india

    ReplyDelete
  8. This website was... how do I say it? Relevant!
    ! Finally I have found something that helped me.
    Appreciate it!
    Here is my webpage ... Online Casino

    ReplyDelete
  9. Natural HGH delivers amazing effects on the body but then production of HGH dramatically decline as one reaches 30 resulting to
    changes which characterize old age. HGH spray is utilized by
    many athletes in order to increase muscle mass, and transform both their body and athletic performance.
    HGH by injection is approved for adults with human growth insufficiency.


    Feel free to visit my page ... Http://hghliving.org

    ReplyDelete
  10. I know this web page offers quality based content and additional data, is there
    any other website which gives such information in quality?


    Also visit my web page; perfume tips

    ReplyDelete
  11. One common transaction that banks report to the IRS is
    interest that you earn from checking or savings account with you to the IRS each year

    Review my website SixFlagsTicketsCoupons.com

    ReplyDelete
  12. I just couldn't leave your site prior to suggesting that I extremely enjoyed the standard information an individual provide on your visitors? Is gonna be again continuously in order to inspect new posts

    My web site; calculate waist to height ratio

    ReplyDelete
  13. Good day I am so excited I found your weblog, I really found you by mistake, while I was
    searching on Bing for something else, Anyways I am here now and would
    just like to say kudos for a incredible post and a all round exciting blog
    (I also love the theme/design), I don't have time to browse it all at the minute but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the superb work.

    Here is my blog; xxx-fuck.net

    ReplyDelete
  14. My brother suggested I might like this blog. He was totally right.
    This post actually made my day. You can not imagine just how much time I had spent for this info!
    Thanks!

    Look at my web page :: nude party girls

    ReplyDelete
  15. Handheld led tap (with hoses) have becomes extremely popular. These can either be attached like a standard bathroom accessories or be pulled down and directed by hand.
    Shower Heads: Factors to Consider Before Buying kitchen tap come with enhanced functionalities, including adjustable spray from a super fine needle spray. These come in innumerable designs and add elegance to any bathroom. Certain factors that one should consider before purchasing a bath tap are:

    ReplyDelete
  16. Antique taps include antique brass finish, Oil-rubbed bronze finish, black bronze finish and also Red bronze finish, you must can find your perfect antique bathroom and kitchen taps in our online store.http://www.cheaptap.co.uk/kitchen-taps-antique-kitchen-taps-c-22_23.html : Cheap Taps Sale Online Store- Offering All Kinds of Taps

    ReplyDelete
  17. These days, homemakers want to add in more type, flair and superiority into their http://www.faucetsmarket.com/bathroom-accessory-faucets-accessories-c-4_33.html. As such, even the faucets are chosen with more care and consideration. With this change in choice, you see the appearance of designer http://www.faucetsmarket.com.

    ReplyDelete