// *********************************************** //
// The grab function for Complex_POLY class //
// *********************************************** //
istream& Complex_POLY::grab(istream& input)
{
Complex_POLY_CELL *temp,*tail;
Complex c,test;
char choice;
unsigned int p;
cout << "Please Enter the Complex element which terminates input:" << endl;
input >> test;
//Find end of list
//see if list is empty but built
if(head==NULL){
head = new Complex_POLY_CELL();
//now we enter the data:
cout << "Input the first element as a Complex: " << endl;
input >> c;
if(!(c==test)){
head->element = c;
cout << "Enter the power you want for this term: " << endl;
input >> p;
head->power = p;
}
}
//find end of list
temp = head;
while(!(temp->next==NULL))
temp = temp->next;
tail = temp;
//temp is not NULL; tail is found
//assume tail stores the last polynomial term
//so degree of polynomial is head->power
//so we add at the tail; these new terms will not be
//in the right order, so later we will have to sort
cout << "Input the next element as a Complex: " << endl;
input >> c;
while(!(c==test)){
temp->next = new Complex_POLY_CELL();
temp->next->element = c;
cout << "Enter the power you want for this term: " << endl;
input >> p;
temp->next->power = p;
temp = temp->next;
cout << "Input the next element as a Complex: " << endl;
input >> c;
}
//polynomial is built on top of original polynomial or as new
//polynomial by adding p+1 new elements
//a_n x^p + ... + a_0 + c_0 x^n+1 ... c_p x^n+p
//apply merge sort to sort according to power
mergesort();
return input;
}
// *********************************************** //
// The print function for Complex_POLY class //
// *********************************************** //
ostream& Complex_POLY::print(ostream& output) const
{
Complex_POLY_CELL *temp;
temp = head;
while(!(temp==NULL)){
output << *temp;
temp = temp->next;
}
return(output);
}