next up previous contents
Next: Mergesort: Up: Implementation: The Complex_POLY_CELL Class: Previous: Polynomial Comparison Operators:

Finding Things in the Polynomial:

    // *************************************** //
    // get the degree of the polynomial        //
    // *************************************** // 
unsigned int Complex_POLY::get_degree()
{
  if(head==NULL) return(0);
  else return(head->power);
}

    // ******************************************* //
    //  find if a power is in the polynomial       //
    // ******************************************* // 
void Complex_POLY::search_power(unsigned int p)
{
  if(get_element_address(p)!=NULL)
    cout << endl << "Polynomial has a power " <<  p  << endl;
  else
    cout << endl << "Polynomial does not have a power p" << endl;    
}

    // ************************************ //
    // protected search agent               //
    // ************************************ //
Complex_POLY_CELL* Complex_POLY::get_element_address(unsigned int p)
{
  Complex_POLY_CELL *temp;
  if(!(head==NULL)){
    temp = head;
    if(p==temp->power){
      return(temp);
      }
    temp = head->next;
    while(!(temp==NULL)){
      if(p==temp->power) return(temp);      
      temp = temp->next;
      }
    }
  //cout << "The term x^" << p << " is not in the polynomial."
  //     << endl;
  return(NULL);
}

    // ************************************ //
    // find address before a given element  //
    // ************************************ // 
Complex_POLY_CELL* Complex_POLY::get_before_element_address(unsigned int p)
{
  Complex_POLY_CELL *temp;
  if(!(head==NULL)){
    temp = head;
    if(p==temp->power){
      //cout << "power is at head of list, so before address is NULL"
      //     << endl;
      return(NULL);
      }
    while(!(temp->next==NULL)){
      if(p==temp->next->power){
        //temp is address of cell before cell containing search_key
        return(temp); 
        }     
      temp = temp->next;
      }
    }
  //cout << "The power " << p << " is not in the polynomial."
  //     << endl;
  return(NULL);
}

    // ************************************ //
    // find address after a given element   //
    // ************************************ //
Complex_POLY_CELL* Complex_POLY::get_after_element_address(unsigned int p) 
{
  Complex_POLY_CELL *temp;
  if(!(head==NULL)){
    temp = head;
    if(p==temp->power){
      return(temp->next);
      }
    temp = temp->next;
    while(!(temp==NULL)){
      if(p==temp->power){
        return(temp->next); 
        }     
      temp = temp->next;
      }
    }
  //cout << "The power " << p << " is not in the polynomial."
  //     << endl;
  return(NULL);
}



Jim Peterson
1999-04-22