1. ## What is wrong with this sort function? (linked list)

the list stores a group of terms in a polynomial

Code:
```struct term
{
int co;    //coefficient of a term
int exp;  //exponent of a term
};

typedef term* termptr;

class Polynomial
{
public:
void sort();
friend istream& operator >> (istream& ins, Polynomial& p1);
//other random stuff you don't need to know for this
private:
};```
I'm trying to sort them once they've been inputted in order of exponent from greatest to least. here's what my sort function looks like:

Code:
```void Polynomial::sort()
{
termptr cursor, current, prev;
int largest = 0;

prev = current;
{
largest = current->exp;
while (cursor)
{
if (cursor->exp > largest)
{
largest = cursor->exp;
ptr = cursor;
current = cursor;
cursor = prev;
}else
{
}
}
prev = current
}
}

istream& operator >> (istream& ins, Polynomial& p1)
{
char x;
string line;
termptr new_term, current;

new_term = new term;
current = new_term;

getline(ins, line);

if (ins)
{
line.erase(remove(line.begin(), line.end(), ' '), line.end());
stringstream ss(line);

while (ss>>current->co >> x >> current->exp)
{
new_term = new term;
}
}
return ins;
}

//here's my application file

int main()
{
Polynomial poly1;

cout << "Enter a polynomial: ";
cin >> poly1;
cout << endl;
poly1.sort();

cout << poly1 << endl;

return 0;
}```
it compiles fine, but when I try to call it in my application file I get a segmentation fault and I can't figure out why

2. Well, let's see. The last time you dereferenced a null pointer, so I'll go with that. Like I said before, when you typedef away the pointer notation, it obscures when you are doing that.

3. I'd love to try and compile this, but I'd prefer to have a bit more code, such as Polynomial::set_head and Polynomial::operator<<.

edit: Some sample input would be nice, too.