GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Dec-2005, 20:37
canucklehead canucklehead is offline
New Member
 
Join Date: Sep 2005
Posts: 10
canucklehead is on a distinguished road

linked list help please!


I'm trying to make a program that uses linked lists in order to add and multiply polynomials together.

This is the code for my multiply term function, which basically just multiplies a polynomial by another term.

CPP / C++ / C Code:
Polynomial& Polynomial::multiply_term(int c, unsigned k){
assert (c != 0);      // can't multiply by 0
  for (Term *p = terms; p != 0; p = p->next) {
    p->coef = p->coef * c;   // multiply coef's together
    p->exp = p->exp + k;    // add exp's together
  }
return *this;
}


I also have a little function that will find a term in the list:
CPP / C++ / C Code:
static Term *find_term(Term *terms, unsigned k){
  Term *prev = 0;
  Term *curr = terms;
  while (curr != 0 && curr->exp < k) {
    prev = curr;
    curr = curr->next;
  }
  return prev;
}

now im trying to get it to add terms together. But i don't know how to do it. Any help from anyone???

This is what my struct looks like in my header file incase that helps you:
CPP / C++ / C Code:
struct Term {
  int coef;       // coefficient (never zero)
  unsigned exp;   // exponent
  Term *next;
};

thanks for any help that anyone can give me.
 

Recent GIDBlogPrepping for deployment by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
linked list error message Krandygrl00 CPP / C++ Forum 4 22-Jun-2005 14:13
search linked list itsmecathys CPP / C++ Forum 20 18-Apr-2005 01:34
adding to linked list from external file cghv C Programming Language 3 09-Mar-2005 13:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:59.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.