next up previous contents
Next: Mergesort Two Chains of Up: Sorting a Polynomial With Previous: Splitting a Polynomial Into

Merging Two Halves:

    // ********************************************************** //
    // merge 2 chains of FLOAT_POLY_CELLS into one chain          //
    // of odd indices and even indices                            //
    // ********************************************************** //
FLOAT_POLY_CELL* FLOAT_POLY::merge(FLOAT_POLY_CELL* A1,FLOAT_POLY_CELL* A2)
{
  FLOAT_POLY_CELL *temp1,*temp2;
  temp1 = A1;
  temp2 = A2;
  if(temp1==NULL){
    return(temp2);
    }
  if(temp2==NULL){
    return(temp1);
    }
  if(temp1->power >= temp2->power){
    //Neither list is empty and A1 has larger
    //first power than A2. So new list is
    //first power of A1 followed by a merge of remaining
    //elements
    temp1->next = merge(temp1->next,temp2);
    return(temp1);
    }
  else{
    temp2->next = merge(temp1,temp2->next);
    return(temp2);
    }
}



Jim Peterson
1999-04-22