I'm trying to merge two linked lists, and I can get it to compile but there are run time errors where my program crashes. I don't get what is happening to where my program dies. I thought I looked over everything, but it might help to have someone else look over it too. I even commented everything out of the function Sum() so it was completely empty except for the return ret; (in hopes or narrowing the source down) and i still got a run time error, i have to be missing something simple. I did some searching but I only found mergesort() functions for things containing one element, and not multiple, or even containing a structure within the class. Anyone see something wrong? If you want to see the member functions just ask.
Code://add two linked classes POLY
POLY Sum(POLY one, POLY two)
{
POLY ret;
int deg1, deg2, high;
double co1,co2;
deg1 = one.degree();
deg2 = two.degree();
if(deg1 >= deg2){
high = deg1;
ret.ChangeDegree(deg1,0);
ret.changecoefficient(one.coefficient(one.degree()),deg1);
}
else{
high = deg2;
ret.ChangeDegree(deg2,0);
ret.changecoefficient(two.coefficient(two.degree()),deg2);
}
high--;
for(high; high >= 0; high--){
ret.append(one.coefficient(high)+two.coefficient(high),high);
}
return ret;
}
class POLY //begin class POLY
{
private:
struct node //begin struct node
{
int pow; //power
double coeff; //coefficient
node *link; //link
}*t; //end struct node, node t
public:
POLY(); //default constructor
POLY(const POLY&); //copy constructor
~POLY(); //destructor
int degree(); //get highest degree
void print(); //print polynomial
double coefficient(int); //get coefficient of specified term
void changecoefficient(double, int);
void mult(double); //multiply polynomial by a constant
void ChangeDegree(int,int); //change an exponent degree from one to another
void append(double,int); //add another link to the list
}; //end class POLY