next up previous contents
Next: Building a List: Up: Implementation: The Complex_POLY_CELL Class: Previous: Deletion of Terms:

Insertion of Terms:

    // ******************************************** //
    // insert and sort a term in the polynomial     //
    // ******************************************** //
int Complex_POLY::insert(Complex new_element,unsigned int q)
{
  Complex_POLY_CELL *current = get_element_address(q);
  if(current!=NULL){//power q is in polynomial
    current->element += new_element;
    }
  else{//power q is not in polynomial so add to head
    //create new poly cell
    Complex_POLY_CELL *after = new Complex_POLY_CELL(new_element,q);
    current = head;
    after->next = current;
    head = after;  
    }
  //now sort polynomial to get in right order.
  mergesort();  
}

    // ************************************************* //
    //   insert a term in the polynomial w/o sorting     //
    // ************************************************* //
int Complex_POLY::insert_nosort(Complex new_element,unsigned int q)
{
  Complex_POLY_CELL *current = get_element_address(q);
  if(current!=NULL){//power q is in polynomial
    current->element += new_element;
    }
  else{//power q is not in polynomial so add to head
    //create new poly cell
    Complex_POLY_CELL *after = new Complex_POLY_CELL(new_element,q);
    current = head;
    after->next = current;
    head = after;  
    }
}



Jim Peterson
1999-04-22